0
这里是我现在就做:最佳实践关闭JDBC结果
public static getConfs(Connection conn, String confNo){
ResultSet rs = null;
try{
rs = conn.createStatement().executeQuery("select col1,col2 from table1");
... // do something with rs
rs.getStatement().close();
rs = conn.createStatement().executeQuery("select col1,col2 from table2");
... // do somthing with rs
rs.getStatement().close();
rs = null;
}catch(Exception e){
throw e;
}finally{
if(rs != null){
try{
rs.getStatement().close();
}catch(SQLException se){
se.printStackTrace();
}
}
}
}
两个问题:
1.我应该重用这样的结果集变量?
2.这样很好的关闭结果集吗?任何更聪明的方式?
考虑[这个答案](http://stackoverflow.com/a/321879/2711488),特别是。 – Holger 2014-10-11 12:10:08