在执行第二次JDBCUtils.closeConnection后 出现空指针异常 求大佬解释一下
public class TestNullEp {
@Test
public void testNullep() {
PreparedStatement ps = null;
Connection connection = null;
ResultSet rs = null;
String sql = "select * from customers where name = '蔡徐坤' ";
try {
connection = JDBCUtils.getConnection();
ps= connection.prepareStatement(sql);
rs = ps.executeQuery();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
JDBCUtils.closeConnection(null, ps, null);
JDBCUtils.closeConnection(connection, null, null);
}
}
}
public static void closeConnection(Connection conn,Statement ps,ResultSet rs) {
try {
if(conn!=null) {
conn.close();
}
}catch (SQLException e) {
e.printStackTrace();
}
try {
if(ps!=null) {
conn.close();
}
}catch (SQLException e) {
e.printStackTrace();
}
try {
if(rs!=null) {
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}