我对春季 F/w 很陌生。我在我的应用程序中使用 spring jdbc 和 spring ORM 作为持久层。我有一个疑问,在多次调用的方法中,我们是否需要关闭结果集对象和语句对象。示例代码是:
public void savedata() throws Throwable
{
Connection connection = null;
try
{
int lastUpdated= jdbcTemplate.queryForInt("select serial_id from serial_details ");
SerialUpdated=jdbcTemplate.queryForInt("select count(* ) from serial_usg where serial_bill is null " +
" and SURROGATE_KEY > "+lastUpdated);
connection = dataSource.getConnection();
String Query = "select * from serial_mst where serial_bill is null and " +
"SURROGATE_KEY > "+ lastUpdated ;
PreparedStatement pStatement = connection.prepareStatement(Query);
ResultSet rs = pStatement.executeQuery();
while(rs.next()){
String data = rs.getString("serial_bill");
}
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}finally{
if(connection != null && !connection.isClosed()){
connection.close();
connection = null;
}
}
我的问题是,如果我多次调用此方法,那么我是否需要关闭语句和结果集方法,或者仅连接对象就足以关闭。