File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes result sets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "result sets" Watch "result sets" New topic
Author

result sets

ryan bohnert
Greenhorn

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
Greenhorn

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
Bartender

Joined: Dec 20, 2006
Posts: 2497
    
    8

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
youtube channel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: result sets