aspose file tools*
The moose likes JDBC and the fly likes Closing a ResultSet object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Closing a ResultSet object" Watch "Closing a ResultSet object" New topic
Author

Closing a ResultSet object

Srinivasa Kadiyala
Ranch Hand

Joined: Jun 10, 2004
Posts: 237
Will the performance will effect if the ResultSet object created is not closed using close() method?

Secondly, I see at many places in the code people are using rs.close()[rs..ResultSet object). ResultSet is an interface and it did not have any implementation for close() method. So when close() method is directly used, how it will work?

Is it necessarry to assign null value to rs object, after we implement rs.close()?

Thanks


Srini
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


Will the performance will effect if the ResultSet object created is not closed using close() method?

Its a good idea to close JDBC resources once you are finished with them. At the very least, close the Connection (since ResultSet etc. objects depend on it) in a finally block.


Secondly, I see at many places in the code people are using rs.close()[rs..ResultSet object). ResultSet is an interface and it did not have any implementation for close() method. So when close() method is directly used, how it will work?

It does have an implementation (otherwise you could not use it). The implementation will be packaged with the Driver files you are using.


Is it necessary to assign null value to rs object, after we implement rs.close()?

It is not necessary to assign a NULL value to any object Java. Just leave clean up of object references to the Garbage Collector.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Srinivasa Kadiyala
Ranch Hand

Joined: Jun 10, 2004
Posts: 237
Hi Paul


It does have an implementation (otherwise you could not use it). The implementation will be packaged with the Driver files you are using.


I could understand here a little bit....implementation is packaged with the driver files..what do you mean by that?

Thanks for the quick reply
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

When you use a JDBC Driver it will (normally) come packaged as a Jar file. Open up the Jar file and somewhere in there will be a class which implements java.sql.ResultSet. It is this class you are using when you "use" ResultSet in your code. Make sense?
Srinivasa Kadiyala
Ranch Hand

Joined: Jun 10, 2004
Posts: 237
Thanks a lot Paul..
Makarand Parab
Ranch Hand

Joined: Dec 10, 2004
Posts: 121
Hi Puthriah Sarma
To get the class name in the jar which implements the ResultSet Interface. In the code when u get the resultset object, just execute this line of code

ResultSet rs = stmt.executeQuery("select * from table");
System.out.println(rs.getClass().getName());

This will give u the name of the class. Enjoy

Regards
Makarand Parab
Nicky Eng
Ranch Hand

Joined: Mar 26, 2005
Posts: 378
i thought ReseultSet object will be "closed" once we close the connection???

let me know if i'm wrong.


From NickyEng
Diploma in Computer Studies
SCJP 1.4
SCWCD 1.4
Formula 1 app by Maxis (Playbook)
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

The API is your friend.

From ResultSet.close()
Note: A ResultSet object is automatically closed by the Statement object that generated it when that Statement object is closed, re-executed, or is used to retrieve the next result from a sequence of multiple results. A ResultSet object is also automatically closed when it is garbage collected.

From Statement.close()
Note: A Statement object is automatically closed when it is garbage collected. When a Statement object is closed, its current ResultSet object, if one exists, is also closed.

Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Closing a ResultSet object
 
Similar Threads
try...catch...finally w/ a result set
Problem in Seperating Core Servlet to Database Query Java
how is close() used?
oracle resultset closing
ResultSet.close()