Hi, first of all I'm new at the forum I hope to help and be helped ;-).
I'm trying to display the values inside an ArrayList on a JSP. I execute a PreparedStatement and I put all the values inside an ArrayList<HashMap<String, Object>>. Once, I have all the values inside the ArrayList I put it in a HttpSession an redirect it to the JSP. In the JSP I try to display the values inside a row of the Arraylist but I get null all the times.
When I do "System.out.println(list.get(1)+"\n"+(list.get(1)).get(1));" I get:
{id=2, pass=muteki, user=muteki}
null
How can I get the values pass and user?
Thank you in advance
/************** JSP *************************/
ArrayList<HashMap<String, Object>> list = (ArrayList<HashMap<String, Object>>) session.getAttribute("list");
System.out.println(list.get(1)+"\n"+(list.get(1)).get(1));
PreparedStatement pst = con
.prepareStatement("select * from users where user=?");
pst.setString(1, user);
ResultSet rs = pst.executeQuery();
ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
list = Conexion.resultSetToArrayList(rs);
HttpSession session = request.getSession();
session.setAttribute("list", list);
response.sendRedirect("/DataBase/dbuser.jsp");
public static ArrayList<HashMap<String, Object>> resultSetToArrayList(ResultSet rs) throws SQLException{
ResultSetMetaData md = rs.getMetaData();
int columns = md.getColumnCount();
ArrayList<HashMap<String, Object>> results = new ArrayList<HashMap<String, Object>>();
while (rs.next()) {
HashMap<String, Object> row = new HashMap<String, Object>();
results.add(row);
for (int i = 1; i <= columns; i++) {
row.put(md.getColumnName(i), rs.getString(i));
}
}
return results;