aspose file tools*
The moose likes JDBC and the fly likes ResultSet usage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ResultSet usage" Watch "ResultSet usage" New topic
Author

ResultSet usage

Dan Parsons
Ranch Hand

Joined: May 30, 2007
Posts: 70
Is it okay to keep creating queries with the same ResultSet Object reference (results)? Here is what I am currently using in my Database statements with Oracle and everything works but was wondering if this is okay where I am using ResultSet results for 3 queries in my Tomcat container:

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18886
    
    8

Sure. It's only a variable, so you can assign as many different objects as you like to it. It's the objects you have to worry about, not the variables. Which is why your code hinted at by "//close results..." is in the wrong place. When you finish using the first ResultSet object, you should close it before you lose the reference to it.
Dan Parsons
Ranch Hand

Joined: May 30, 2007
Posts: 70
Thanks, I had to change it to where I create 3 different ResultSets with the same Statement object and closing the 3 different ResultSet objects in a finally block. Here is what I am currently using in my Database statements with Oracle and everything works great. But I am wondering if this will create Database resource leakages or other issues:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ResultSet usage