【发布时间】:2015-10-02 07:21:55
【问题描述】:
是否需要在一个 db.getConnection() 中关闭 ResultSet 和 PreparedStatement?下面的例子:
Connection conn = db.getConnection();
PreparedStatement pstmt = conn.prepareStatement(firstsql);
ResultSet r = pstmt.executeQuery();
// do something with the ResultSet
r.close();
pstmt.close(); // do I need close the r and pstmt here?
PreparedStatement pstmt = conn.prepareStatement(secondsql);
ResultSet r = pstmt.executeQuery();
// do something with the ResultSet again
r.close();
pstmt.close();
conn.close();
return null;
第5行和第6行的代码有必要吗?
【问题讨论】:
标签: java database jdbc prepared-statement