【发布时间】:2014-12-06 06:24:20
【问题描述】:
这是我现在的做法:
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.这样关闭结果集好吗?有什么更聪明的方法吗?
【问题讨论】:
-
特别考虑this answer。