wood burning stoves 2.0*
The moose likes JDBC and the fly likes Could resultset be returned from another method? 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 "Could resultset be returned from another method?" Watch "Could resultset be returned from another method?" New topic

Could resultset be returned from another method?

Ziyang Zhang
Ranch Hand

Joined: Jul 17, 2010
Posts: 47
I wrote a utility class to get resultset:

So that in other class, I can invoke this method to get resultset:

But this does not work, I get SQLException if I invoke next() method on the returned resultset.

I searched the reason, and i think this may be the reason:
Or you can look at CachedRowSet, because ResultSet object is bound with the Statement object. However, CacheRowset is independent and made for passing across layers.

JDBC Tutorail says:

A CachedRowSet classa disconnected rowset that caches its data in memory; not suitable for very large data sets, but an ideal way to provide thin Java clients, such as a Personal Digital Assistant (PDA) or Network Computer (NC), with tabular data

Could somebody explain more to me?
Thanks a lot,

Enjoy life!
Lester Burnham

Joined: Oct 14, 2008
Posts: 1337
A ResultSet can certainly be returned from a method, but if you close the connection, then all associated resources (ResultSets, Statements, etc.) will be closed as well.
Don't get me started about those stupid light bulbs.
subject: Could resultset be returned from another method?
Similar Threads
How to specify the name of the database
Oracle -- Closing Statements
jsf and database connection problem
Right or not? Servlets share the same object.