• Post Reply Bookmark Topic Watch Topic
  • New Topic

Resultset in Collections  RSS feed

 
Abhinav mathur
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
I have a resultset which I want to hold in a java collection rather than resultset object after query.
Whats the best way of holding the Resultset data, It can be assumed that there are going to be good number of rows and columns of varying types.

regards,
Abhinav Mathur
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you have to do something like:

You might get fancy and query the metadata to get column names and types. If you need that, maybe you'd make an objct that can hold metadata and a set of rows. An awful lot like a ResultSet but not tied to the db at all.

I'm sure there are some open source frameworks out there if you google correctly.
 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's an old class I made to wrap the ResultSet using collections, it uses Vector, but perhaps needs updating to ArrayList if you want.




which is populated from the ResultSet something like this...



It's not great, but it works. One day I might update it, but as pointed out already there are probably much better implementations available in other 3rd party APIs (JDO?)

HTH
 
Sean Sullivan
Ranch Hand
Posts: 427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can accomplish this using Diaz

http://diaz.sourceforge.net/

Diaz will return a List of net.sf.Row objects.

Note: diaz requires J2SE 5.0
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!