-2

I have for example the following code line

ResultSet rs = stmt.executeQuery("SELECT * FROM item WHERE itemID='"+ X +"'");

if item table scheme is: ItemID,itemName,Count,location

how does the row from the table "sit" in the ResultSet? is there a way to take the entire row and push it to the first cell of ArrayList (that is the value i must return and i can not change it, for other queries with multiple line results each line will be in a different cell of the array)?

Kapil Khandelwal
  • 15,958
  • 2
  • 45
  • 52
jeff ranz
  • 55
  • 1
  • 1
  • 5
  • 1
    see the tutorial code here - http://docs.oracle.com/javase/tutorial/jdbc/basics/retrieving.html – radai Jan 07 '13 at 10:18

1 Answers1

0

you can iterate over your resultset using ResultSet.next() and get the row information on every iteration and add it into your array list.

List<YourObj> ref = new ArrayList<>();
ResultSet rs = stmt.executeQuery("SELECT * FROM item WHERE itemID='"+ X +"'");
while(rs.next())
      ref.add(new YourObj(rs.getName(), rs.getWhatever()));
}

Here's the reference from Oracle Trails

PermGenError
  • 45,977
  • 8
  • 87
  • 106