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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Closing ResultSet  questions" Watch "Closing ResultSet  questions" New topic
Author

Closing ResultSet questions

john mattucci
Ranch Hand

Joined: Nov 03, 2000
Posts: 331
I have the following 2 bits of code. Currently I close rs only in finally in addition to all ps and connection. Thank you for your time.

1/


2/

Tim LeMaster
Ranch Hand

Joined: Aug 31, 2006
Posts: 226
In my opinion

code 1: Yes you should close the result set before assigning a new ResultSet object to the rs variable.

code 2: Yep same as above. Except in the case I would close the statement also. But I would change it to make sure your prepared statement can be cached. see below.

Of course according to the specs if you close a statement its result set will also be closed so if you are closing your statement in finally this probably isn't much of a problem. But I feel its always best to call close() explicitly on all JDBC objects.

I'd rewrite case 2 to be more like

[ December 06, 2006: Message edited by: Tim LeMaster ]
 
 
subject: Closing ResultSet questions
 
Similar Threads
refresh table doesn't work
Using a Bean for Retrieving Results Sets - Best Approach
Url cannot be null error :(
PreparedStatement-Statement
prepared statement