• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Closing a ResultSet object

 
Srinivasa Kadiyala
Ranch Hand
Posts: 237
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Srinivasa Kadiyala
Ranch Hand
Posts: 237
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 237
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Paul..
 
Makarand Parab
Ranch Hand
Posts: 121
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 378
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i thought ReseultSet object will be "closed" once we close the connection???

let me know if i'm wrong.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic