storing the more dan 1 rows retrieved from database in java

hii want to store the rows retrieved from the database into my java prog.there are more dan 1 rows.how can i do dat using resultset?regardsambika
[180 byte] By [ambika_mullasseria] at [2007-11-27 8:48:37]
# 1

You need to iterate result set. Result set will iterate on rows. For each row, you will need to get the column values in some data structure.

Here is an example: I have a table employee with fields ID, Name and Age. I need to get details of all the rows :

***************************************

try{

Connection con = DriverManager.getConnection("url", "userName", "passWord");

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery("SELECT * FROM EMPLOYEE");

ArrayList employeeDetail = null;

ArrayList employees = new ArrayList();

while(rs.next())

{

int id = rs.getInt("ID");

String name = rs.getString("NAME");

int age = rs.getInt("AGE");

employeeDetail = new ArrayList();

employeeDetail.add(new Integer(id));

employeeDetail.add(name);

employeeDetail.add(new Integer(add));

employees.add(employeeDetail);

}

}catch(SQLException sqe)

{

//Do something with exception

}

***********************************

Hope it will help you understand how to do it.

vineet.mangala at 2007-7-12 20:56:03 > top of Java-index,Java Essentials,New To Java...
# 2
What do you mean by "store"? Are you going to put the data into another table? Of are you asking how to loop through a result set?
Dick_Adamsa at 2007-7-12 20:56:04 > top of Java-index,Java Essentials,New To Java...