wood burning stoves 2.0*
The moose likes JDBC and the fly likes Close a resultset in a function while returning  the values 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 » Databases » JDBC
Bookmark "Close a resultset in a function while returning  the values" Watch "Close a resultset in a function while returning  the values" New topic
Author

Close a resultset in a function while returning the values

Gorakshanath Pandey
Greenhorn

Joined: Feb 25, 2004
Posts: 11
Is there
a way to return a ResultSet() Object from a function like
Public static void(?) Fn()
{
Statement stmt;
ResultSet rs
String Sql
...
...
rs=stmt.executeQuer(sql)
return rs; ///How to return value after clossing....
}
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
As you know, result sets are closed when the connection is closed ... so, assuming that your connection isn't closed, you can just return the result set and use it however you want, closing it when you're done.
If you need to close the connection, or return it to the pool, you'll have to save all that information in some sort of java beans or whatever you want (domain objects, beats me ...).


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
The simple answer is yes. You can return a ResultSet object from a method like this:

But you have to be careful about passing around references to resources such as open ResultSetS as mentioned by Wayne in this thread.


Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
You of course wouldn't want to close your result set until you're done with it, though.
Dana Hanna
Ranch Hand

Joined: Feb 28, 2003
Posts: 227
If you don't want to build domain objects, check out the javax.sql.RowSet interface of JDBC 2.0.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Close a resultset in a function while returning the values
 
Similar Threads
How to check record exists
Something wrong in returning ResultSet
Resultset question
ResulSet issue
Calling Oracle Function that returns %ROWTYPE