2014-09-23 318 views
1

如果我使用Hibernate,必須關閉ResultSetCallableStatement嗎?例如:關閉resultSet和callableStatement

CallableStatement cstmt = sessionFactory.getCurrentSession() 
       .connection() 
       .prepareCall("{? = call PREQUEST.GetRequestList(?,?)}"); 
     cstmt.registerOutParameter(1, OracleTypes.VARCHAR); 
     cstmt.setString(2, sessionId);  
     cstmt.executeUpdate(); 
     cstmt.close(); // Closing 
     return cstmt.getString(1); 
+0

注意:從會話中獲取[connection](http://docs.jboss.org/hibernate/orm/3.5/javadocs/org/hibernate/Session.html#connection())被標記爲已棄用且已計劃去除。 – A4L 2014-09-23 07:31:43

回答

2

Connection.close()方法的JavaDoc的「立即釋放此Connection對象的數據庫和JDBC資源,而不是等待它們被自動釋放。」開頭

因此,如果您關閉()連接,所有獲取的對象,如StatementsResultSets將被關閉。

但是,如果您使用connection pool,則close()方法將返回到pool的連接,並且不會實際關閉連接。在這種情況下,相關對象可能保持打開狀態。在這種情況下,我認爲,最好手動關閉它們。

相關問題