Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

storing Resultset in a collection

 
surendar prabu
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paul Clapham
Sheriff
Posts: 21137
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rajah Nagur
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Joshy Thomas
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
dhoom dhoomm
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic