DB.java
public static ResultSet getResultSet(Statement stmt, String sql) {
ResultSet rs = null;
try {
if (stmt != null) {
rs = stmt.executeQuery(sql);
}
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
//stmt.close();//返回的rs 在调用的文件里无法使用;
}
//而在调用的文件内,关闭stmt,对应的 PreparedStatement 资源也会自动关闭;同样若只关闭Connection,则与之对应的stmt,rs等相关资源也会被关闭,但这显然不是良好的编程习惯;