converting result set to list
Posted
by akshay
on Stack Overflow
See other posts from Stack Overflow
or by akshay
Published on 2010-05-29T05:15:44Z
Indexed on
2010/05/29
5:22 UTC
Read the original article
Hit count: 226
how can i conver result set to list? i am using following code but its not working properly
private List<User> convertToList(ResultSet rs) {
List<User> userList = new ArrayList();
User user = new User();
try {
while (rs.next()) {
user.setId(rs.getInt("id"));
user.setUsername(rs.getString("username"));
user.setFname(rs.getString("fname"));
user.setLname(rs.getString("lname"));
user.setUsertype(rs.getInt("usertype"));
user.setPasswd(rs.getString("passwd"));
user.setEmail(rs.getString("email"));
userList.add(user);
}
} catch (SQLException ex) {
Logger.getLogger(UserDAO.class.getName()).log(Level.SEVERE, null, ex);
} finally {
closeConnection();
}
return userList;
}
© Stack Overflow or respective owner