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 storing Resultset in a collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "storing Resultset in a collection" Watch "storing Resultset in a collection" New topic
Author

storing Resultset in a collection

surendar prabu
Ranch Hand

Joined: Jul 24, 2006
Posts: 102
I need to store my resultset in a collection object.is there any direct method available for this? or should i explicitly type cast result set to a collection?

regards,
surendar


SCJP 1.4
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18121
    
    8

No to both questions.

What you should do is this: read each row of the ResultSet; convert that row to an object of some class that is suitable to your program's requirements; add that object to a collection.
Chetan Natu
Greenhorn

Joined: Dec 03, 2005
Posts: 19
Don't forget to read the resultsetmetadata to extract the field name, size, type etc.,etc., Which will be handy if you want to generate a generalised code to work with any database


Never Remember the failure
Never Forget the mistake
Rajah Nagur
Ranch Hand

Joined: Nov 06, 2002
Posts: 239
Originally posted by surendar prabu:
I need to store my resultset in a collection object.is there any direct method available for this? or should i explicitly type cast result set to a collection?

regards,
surendar


I think what you need is disconnected rowset. Rowset extends ResultSet. You can definitely keep this Rowset in any collection object. There is no need to typecast while storing, but while retrieving you need to downcast.

This is what I understand from your question...hope it helps.
[ August 09, 2006: Message edited by: Rajah Nagur ]

You can't wake a person who is <b><i>pretending</i></b> to be asleep.<br />Like what <b>"it"</b> does not like - <i> Gurdjieff </i>
Joshy Thomas
Greenhorn

Joined: Jul 23, 2004
Posts: 13
If you can try using the Apache QueryRunner, which is part of the dbutils, jakarta commons project.

You can get examples at http://jakarta.apache.org/commons/dbutils/examples.html


<a href="http://www.FindTaxService.com" target="_blank" rel="nofollow">Free Tax Software</a>
dhoom dhoomm
Greenhorn

Joined: Sep 05, 2012
Posts: 2
I have created a class for my project, i hope it might be useful for you..
Also make sure, the rows fetched are limited or it may eat up your memory..



Also, i am open to suggestions...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: storing Resultset in a collection
 
Similar Threads
Serializing ResutSet
Returning the ResultSet to the JSP
Resultset elements not getting displayed in jsp when using JSP/JSTL
Declare a PUBLIC Result Set
Try/Catch/Return