• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Close a resultset in a function while returning the values

 
Gorakshanath Pandey
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ...).
 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You of course wouldn't want to close your result set until you're done with it, though.
 
Dana Hanna
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't want to build domain objects, check out the javax.sql.RowSet interface of JDBC 2.0.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic