| Author |
How to put a list of data retrieve from database into arraylist
|
jay lai
Ranch Hand
Joined: Apr 04, 2002
Posts: 180
|
|
Hello, I am writing a class that invoke a storeprocedure return multiple reccords from database. While (rs.next()) { string test1=rs.getString("testValueFromDB"); string test2=rs.getString("test2ValueFromDB"); string test3=rs.getString("test3ValueFromDB"); } What do I do to put this resultset into an array and loope through it? Any hints or suggestion is greatly appreciated.
|
 |
Nadeem Awad
Ranch Hand
Joined: Jan 09, 2005
Posts: 74
|
|
Originally posted by jamie lee: What do I do to put this resultset into an array and loope through it? Any hints or suggestion is greatly appreciated.
I think the best way is to wrap the String values in one object for each row, and then add the objects to the ArrayList. Something like this: Best regards,
|
Share Knowledge to gain it.<br /> <br />SCJP 1.2, SCDJWS 1.4, SCWCD 1.4, SCBCD 1.3, ICAD
|
 |
Scott Selikoff
Saloon Keeper
Joined: Oct 23, 2005
Posts: 3652
|
|
I agreed with Nadeem's solution, except the creation of a "MyValueObject" really depends on how frequently you need this object. Its it of a very temporary nature and you know the number of columns returned by the query, I suggest a typed array such as: This is just from my experiences in practice, only create a new class if it is appropriate to do so. It depends on a number of other factors though.
|
My Blog: Down Home Country Coding with Scott Selikoff
|
 |
jay lai
Ranch Hand
Joined: Apr 04, 2002
Posts: 180
|
|
Thanks Both, I am going to try out. Best Regards
|
 |
 |
|
|
subject: How to put a list of data retrieve from database into arraylist
|
|
|