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
posted
0
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
posted
0
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
posted
0
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
posted
0
cool thanks for that
RB
Tony Morris
Ranch Hand
Joined: Sep 24, 2003
Posts: 1608
posted
0
Why do people insist on using Vector still? It is well out of date - 7 years in fact.
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