• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Close a resultset in a function while returning the values

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
}
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ...).
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You of course wouldn't want to close your result set until you're done with it, though.
 
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic