wood burning stoves 2.0*
The moose likes Performance and the fly likes Closing  DBObjects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Closing  DBObjects" Watch "Closing  DBObjects" New topic
Author

Closing DBObjects

Jotty Tharakan
Greenhorn

Joined: Dec 14, 2001
Posts: 17
If you close the connection whether all related DBObjects like Resultset,statement objects are also closed or we need to close each and every one of them explicitly.
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

It is good practice to close the object as soon as you are finished with it to free up the database resource as soon as possible.
Jamie
Jotty Tharakan
Greenhorn

Joined: Dec 14, 2001
Posts: 17
Jamie ,
I'm agreeing with u but is it necessary to close all objects like resultset and statement objects or closing the connection itself will close all related objects ?
Can u pls clear this point
Shashank Hiwarkar
Ranch Hand

Joined: Feb 17, 2002
Posts: 32
Jotty,
I aggree to Jamie, We should free the database resources as soon as possible.
But look how we declare statements amd resultset
Statement stmt=connection.createStatement();
ResultSet rs=stmt.getResultSet();
that means statement and resultset are created with the help of connection object.
When you are saying "connection.close()"
you don't have to explicitly close Statements and ResultSet. The resources will be freed at the same time.
If anybody has some other views please let me know.


Shashank Hiwarkar<br />SCJP, SCWCD
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

the connection object will invoke the methods Statement.close() and ResultSet.close() on all associated statements/resultsets when you invoke the method Connection.close(). But why would you not release the DB resources at the earliest possible time? By not doing so, it will make your code more less readable and definitely deplete network/DB performance on higher traffic applications. Some DB's are affected more than others when it comes to increased traffic.
Jamie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Closing DBObjects
 
Similar Threads
Web service client implementation (Connection refused error)
face to face with a moose
Study Guide for IBM 287
ConnectionPool causing memory leak
Reg PrintWriter