Do I have to close ResultSet
and CallableStatement
if I use Hibernate? For example:
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);
The JavaDoc for the Connection.close()
method starts with "Releases this Connection object's database and JDBC
resources immediately instead of waiting for them to be automatically released."
Therefore, if you close() the connection, all the acquired objects, such as Statements
and ResultSets
will be closed.
However, if you use connection pool
, the close()
method returns the connection to the pool
and doesn't actually close the connection. In this case dependent objects may be left open. In this case, I think, it is better to close them manually.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments