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}

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");
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);
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>();


			for (int i = 1; i <= columns; i++) {

				row.put(md.getColumnName(i), rs.getString(i));


		return results;
5 Years
Discussion Span
Last Post by khamsinh

list.get(1) returns the HashMap that is in position 1 in the ArrayList.
When you print that HashMap you get its default output, which is a list of the key=value pairs in the HashMap
{id=2, pass=muteki, user=muteki}

list.get(1).get(1) gets the first HashMap then calls get(1) on that HashMap.
Now check out the JavaDoc for HashMap. Unlike ArrayList the parameter for HashMap's get is a key, not an integer position. So you are trying to retrieve the value whose key is the Integer 1, and there's no such key in the map, which is why it returns null.
You need to use something like

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.