File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How do I put a ResultSet into an Array? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "How do I put a ResultSet into an Array?" Watch "How do I put a ResultSet into an Array?" New topic
Author

How do I put a ResultSet into an Array?

rastas biggs
Ranch Hand

Joined: Sep 24, 2004
Posts: 41
I need to get rows of data from the database and place in an Arraylist.

I'm not sure if an ArrayList is the right choice, I need to get my ArrayList and call the Column names to place the out put in a sorted order to print to a file for another system to process so it is imperative that data is in a specific order.

Can some one point me in the right direction.

RB
jefff willis
Ranch Hand

Joined: Sep 29, 2004
Posts: 113
Storing the output into an array, a list, or a vector is all simple enough, but you should let the DB do the sorting for you.

When you query for the data, use the ORDER BY phrase in your statement
rastas biggs
Ranch Hand

Joined: Sep 24, 2004
Posts: 41
Thanks Jeff, do you have some example code of placing the result set into an array or vector

RB
jefff willis
Ranch Hand

Joined: Sep 29, 2004
Posts: 113
Here is a code snippit:



This is just rudimentry. modify it to fit your needs.
rastas biggs
Ranch Hand

Joined: Sep 24, 2004
Posts: 41
cool thanks for that

RB
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
Why do people insist on using Vector still?
It is well out of date - 7 years in fact.

Why oh why oh why?


Tony Morris
Java Q&A (FAQ, Trivia)
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
If you get multiple columns from your query you'll probably want to make a class that represents one row and put instances of that class into the collection:

If you really need to sort MyThings after the query (I agree with making the database do the sort if at all possible!) look into implementing Comparable in MyThing and using an ordered collection like TreeSet. Holler if that's not enough to go on.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
Consider Paul's rocket mass heater.
 
subject: How do I put a ResultSet into an Array?