File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases 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 Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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.
I agree. Here's the link:
subject: Could resultset be returned from another method?