You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I haven't worked with connectionpools a lot, and I stumbled upon the question what I have to do in the finally-block of queries. So without a connection-pool I closed the PreparedStatement, the ResultSet and the Connection. Which of them do I have to close in the finally-block while using HikariCP as ConnectionPool?
Thanks in Advance!
Scrayos
The text was updated successfully, but these errors were encountered:
In general it is always a good practice to release resources like Statements and ResultSets quickly by explicitly closing them. Having said that, the contract of JDBC states that closing a Statement will automatically close open ResultSets, and that closing a Connection will automatically close open Statements. So in theory you only ever need to close the Connection in the finally, and it will close open Statements which will close open ResultSets.
In a Connection pool, even though closing a Connection does not truly close it, and instead returns it to the pool, a properly implemented connection pool should close open Statements in just the same way as standard JDBC when the connection is returned to the pool.
You can basically leave your code just as it is. One of the contracts of a connection pool is that changing from a standard DataSource to a pooled DataSource should require no changes to the code that uses it.
Hey brettwooldridge,
I haven't worked with connectionpools a lot, and I stumbled upon the question what I have to do in the finally-block of queries. So without a connection-pool I closed the PreparedStatement, the ResultSet and the Connection. Which of them do I have to close in the finally-block while using HikariCP as ConnectionPool?
Thanks in Advance!
Scrayos
The text was updated successfully, but these errors were encountered: