Nojin Kokkatt wrote: if the connection parameter close is it automatically close the Statement and result set ?
Java 8 SE Doc wrote:void close() throws SQLException
Releases this Connection object's database and JDBC resources immediately instead of waiting for them to be automatically released.
Java 8 SE Doc wrote:Note:When a Statement object is closed, its current ResultSet object, if one exists, is also closed.
Stephan van Hulst wrote:By nulling them out before closing them, you won't be able to create new statements until the garbage collector collects the old ones.
Stephan van Hulst wrote:
The leak is not permanent, but it's bad anyway.
Ganesh Patekar wrote:Yes it closes Statement and ResultSet automatically but it is recommended to close them explicitly because when you close them immediately it makes them eligible for GC so saves memory.
Dave Tolls wrote:I can't think of anything about a connection that would prevent you from creating a new Statement just because you've null'd a previous reference.
And when you've had to track down your first ORA-1000 (Max open cursors exceeded), or your database's equivalent, you'll know why it's bad.
Stephan van Hulst wrote:[
I think this is what I was referring to.
but I found this here in Java 8 doc link which saysStephan van Hulst wrote:As far as I know, closing a connection does not close statements or result sets.
What precisely do they mean by this? may be I misunderstood thatJava 8 SE Doc wrote:void close() throws SQLException
Releases this Connection object's database and JDBC resources immediately instead of waiting for them to be automatically released.
Ganesh Patekar wrote:conclusion:
Output proves that closing Connection closes Statement and ResultSet for sure. So perhaps ResultSet and Statement are JDBC resources according to doc.
Yes some implementation returns Connection to Connection pool on close() method. Completely AgreedStephan van Hulst wrote:It may very well depend on the database driver though. To be certain, I think it's good practice to always properly close your statements and result sets separately from the connection.
Ohh, I see. Thank you for clearing my confusionStephan van Hulst wrote:No, I'm talking about the relation between connections and statements. It could be that some drivers don't close statements if you close the connection, even if the connection is not merely returned to the pool.
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|