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;
}