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 result sets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "result sets" Watch "result sets" New topic

result sets

ryan bohnert

Joined: Feb 27, 2008
Posts: 19
I have a class called Client, where I am making a call to another class called DB.

I am passing in a select statement to the DB class, the DB class takes care of the driver, login, connection, statement, result set, and closing work.

But I don't want the DB class to have to loop through the result, i want the client to do this.

So how exactly do i give them the data from the DB class and still maintain doing the closing work. Do i need to put the results set in a collection and return that back to the Client class, so I can still close everything i need in the DB class. I know i have to someone move the data from result set because once it closes it will be gone.

Any suggestions would be great?
Kalyani Sailendra

Joined: Mar 06, 2008
Posts: 2
The normal practice is to call the getconnection method of the DB class in the client, do the processing on the resultset and then call the method of DB class to take care of closing the connection or close the connection in the client class.

In your situation, every time the resultset needs to be copied in to a different object and passed to the calling class.
Jan Cumps

Joined: Dec 20, 2006
Posts: 2565

The CachedRowSet allows you to iterate over the results of a query when the database connection is unavailable.
Get disconnected with CachedRowSet.

Regards, Jan

OCUP UML fundamental and ITIL foundation
I agree. Here's the link:
subject: result sets
It's not a secret anymore!