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