how to show data in array format?

Hello,

I have two questions,

1) How to count the no. of records returned by a Query in JSP ie mysql_num_rows(query) is done in PHP and

2) How to put data in array form after retrieving it from the database.

I had done the following code to put in array format.

I have a list of usernames that comes from the database and i need to keep it in the array list.

ie.

I have a query that results more than 10 records. and the result for this is rs.

I have done like this,

String[] user_name = null;

int index = 0;

while(rs.next())

{

user_name[index] = rs.getString("Username");

index++;

}

But this resulted an error in my page. Is anything wrong in my code or can u plz give me the instructions how to keep data in array formats like in above case.

Message was edited by:

yubak123

[893 byte] By [yubak123a] at [2007-11-27 4:03:34]
# 1

Use Collections. Preferably Collections of DTO's.

List<User> users = new ArrayList<User>();

while (resultSet.next()) {

User user = new User();

user.setId(resultSet.getLong("id"));

user.setName(resultSet.getString("name"));

user.setAge(resultSet.getInt("age"));

...

users.add(user);

}

You can count the records byint size = users.size();

Also see http://java.sun.com/j2se/1.5.0/docs/guide/collections/

BalusCa at 2007-7-12 9:08:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...