• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to put a list of data retrieve from database into arraylist

 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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,
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Both,
I am going to try out.
Best Regards
 
grapes are vegan food pellets. Eat this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic