Is returning ResultSet possible?

Q

qazmlp

Is is safe to return a ResultSet from a member function of my class?
Can it cause memory leaks?
 
E

Erwin Moller

qazmlp said:
Is is safe to return a ResultSet from a member function of my class?
Can it cause memory leaks?

AFAIK:
Resultsets use a Connection which should be closed nicely.
That could be a problem.
So if you are going to pass around Resultset, be sure you do all the stuff
needed, like errorhandling (try/catch/finally) everywhere this Resultset
goes. You can probably come up with a good design for that, but it could be
a lot of work.

a workaround:
You could copy the resultset of course into your own custummade object, and
pass that object around, which is a lot safer, but increases the memory/cpu
load of course, because of the copying.
That is how I handled that problem once.

In my case I developed some custom Taghandlers which needed databaseaccess,
and because of the number of methods that could be called, and the number
of 'uncertain' circumstances, and the errorhandling, I didn't want the
resultset to be an instancevariable. SO I made another object in which to
store all the data from the resultset.

I used Stringrepresentation/numberrepresentation for all fields and made
some basic methods to fill that object with a resultset, get values out of
it, etc.
If that will do the trick for you depends on your application.
In my case it was sufficient to use Strings and numbers.

(If I remember well there are also results around that are not coupled to a
connection. Check that at Sun or somewhere.)

Just my 2 cents

Regards,
Erwin Moller
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top