Two Laptop Bag
The moose likes Java in General and the fly likes Populate the data into an ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Populate the data into an ArrayList" Watch "Populate the data into an ArrayList" New topic
Author

Populate the data into an ArrayList

Deepa Sindhu
Greenhorn

Joined: Aug 24, 2006
Posts: 2
My requirement is I want to connect to a table in the data base and retrive the column of data for a particula condition.
ex: Select TxnId from Table t where t.bachNo = x;

here TxnId is a column name of the table. It retrives 120 records(Imagine)

Now I have to store these values into an ArrayList .

Please give me the solution.
I am very much Thank full to you .

Deepa
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
OK, I will give you the solution for the bargain price of $1,000,000 US.



"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
OK, what is the problem?

1. connecting to the database
2. retrieving the records
3. adding them to an Arraylist
4. other
5. all of the above
Deepa Sindhu
Greenhorn

Joined: Aug 24, 2006
Posts: 2
Originally posted by Michael Dunn:
OK, what is the problem?

1. connecting to the database
2. retrieving the records
3. adding them to an Arraylist
4. other
5. all of the above


After getting the column data I have to add those data into ArrayList . Please help me.

Deepa
Felx Devasia
Greenhorn

Joined: Aug 13, 2006
Posts: 2
I guess you are currently holding data in a resultset(say, rs). For populating arrayList, you need to loop loop thru the resultset.
eg:
ArrayList resultHolder=new ArrayList();
if(rs!=null){
while(rs.next){
resultHolder.add(rs.getString(1));//gets first element from resultset
}
}
I personally advice you to look more into JDBC and collections framework. Sun provides excellent tutorials for both.

Regards,
Felix.
[ August 24, 2006: Message edited by: Felx Devasia ]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Populate the data into an ArrayList
 
Similar Threads
Apache Velocity --How to access data from ArrayList
Reading Files
how to get the table column name as key of the hasmap and values as arraylist in hibernate
is possible to add Arraylist to JTable?
reusability of object