Question: I have a simple statement in a servlet file that will go through the database and get the result set

```
ResultSet AssignmentList = stmt.executeQuery("SELECT * FROM Assignments WHERE " + projectID + "= Pid;");
request.setAttribute("assignmentList", AssignmentList);

```

As you can see I'm sending the `ResultSet` to a JSP file. And in that JSP file I tried to iterate through it like this.

```
<table class="CSSTableGenerator">
    <thead>
    <tr>
        <th>Aid</th>
        <th>Title</th>
        <th>Task</th>
        <th>ID of User Responsible</th>
    </tr>
    </thead>
    <tbody>

    <c:forEach items="${assignmentList}" var="item">
        <tr>
            <td>${item.Aid}</td>
            <td>${item.Title}</td>
            <td>${item.Task}</td>
            <td> ${item.UserID}</td>            
        </tr>
    </c:forEach>

    </tbody>
</table>

```

but when I do that I get an error. 
Am I suppose to iterating in wrong way, or is it not possible to iterate through a `ResultSet`.

Answer: 
There a class somewhere in JSP called Results that does exactly what you need. You construct it from a ResultSet, you can close the ResultSet and the connection, and the Results has an Iterable array of rows that are themselves maps.
Assuming you have a fairly standard `ItemBean` (I made everything a String, except projectId). Then, I would probably start with a [`PreparedStatement`](http://docs.oracle.com/javase/7/docs/api/java/sql/PreparedStatement.html) in a DAO helper method like so

```
private static List<ItemBean> queryForItems(
    Connection conn, int projectId) {
  PreparedStatement ps = null;
  ResultSet rs = null;
  // The Query is using a bind parameter
  final String ITEM_SQL = "SELECT * FROM Assignments WHERE Pid = ?";

  // This is the Diamond Operator... if pre Java 7, use new ArrayList<ItemBean>();
  List<ItemBean> al = new ArrayList<>();
  try {
    // Prepare the statement
    ps = conn.prepareStatement(ITEM_SQL);
    ps.setInt(1, projectId); // <-- bind the parameter
    rs = ps.executeQuery();
    while (rs.next()) { // <-- "Iterate" the ResultSet
      ItemBean ib = new ItemBean();
      ib.setPid(projectId);
      ib.setAid(rs.getString("Aid"));
      ib.setTitle(rs.getString("Title"));
      ib.setTask(rs.getString("Task"));
      ib.setUserId(rs.getString("UserID"));
    }
  } catch (SQLException se) {
    System.err.println("Error with " + ITEM_SQL + " and projectId = " + projectId);
    se.printStackTrace(System.err);
  } finally {
    // Clean up!
    try {
      rs.close();
    } catch (SQLException ignored) {
    }
    try {
      ps.close();
    } catch (SQLException ignored) {
    }
  }
  return al;
}

```