title: Java ResultSet already closed exception while querying user data
body: <p>As I've started in the title, while I'm querying for user data in my java application, I get following message: <em>"Operation not allowed after ResultSet closed"</em>.</p>
  
  <p>I know that this is happens if you try to have more ResultSets opened at the same time.</p>
  
  <p>Here is my current code:</p>
  
  <p>App calls getProject("..."), other 2 methods are there just for help. I'm using 2 classes because there is much more code, this is just one example of exception I get.</p>
  
  <p><em>Please note that I've translated variable names, etc. for better understanding, I hope I didn't miss anything.</em></p>
  
  <pre><code>/* Class which reads project data */
  
  public Project getProject(String name) {
      ResultSet result = null;
      try {
          // executing query for project data
          // SELECT * FROM Project WHERE name=name
          result = statement.executeQuery(generateSelect(tProject.tableName,
                  "*", tProject.name, name));
          // if cursor can't move to first place,
          // that means that project was not found
          if (!result.first())
              return null;
          return user.usersInProject(new Project(result.getInt(1), result
                  .getString(2)));
      } catch (SQLException e) {
          e.printStackTrace();
          return null;
      } catch (BadAttributeValueExpException e) {
          e.printStackTrace();
          return null;
      } finally {
          // closing the ResultSet
          try {
              if (result != null)
                  result.close();
          } catch (SQLException e) {
          }
      }
  }
  
  /* End of class */
  
  /* Class which reads user data */
  
  public Project usersInProject(Project p) {
      ResultSet result = null;
      try {
          // executing query for users in project
          // SELECT ID_User FROM Project_User WHERE ID_Project=p.getID()
          result = statement.executeQuery(generateSelect(
                  tProject_User.tableName, tProject_User.id_user,
                  tProject_User.id_project, String.valueOf(p.getID())));
  
          ArrayList&lt;User&gt; alUsers = new ArrayList&lt;User&gt;();
          // looping through all results and adding them to array
          while (result.next()) { // here java gets ResultSet closed exception
              int id = result.getInt(1);
              if (id &gt; 0)
                  alUsers.add(getUser(id));
          }
          // if no user data was read, project from parameter is returned
          // without any new user data
          if (alUsers.size() == 0)
              return p;
          // array of users is added to the object,
          // then whole object is returned
          p.addUsers(alUsers.toArray(new User[alUsers.size()]));
          return p;
      } catch (SQLException e) {
          e.printStackTrace();
          return p;
      } finally {
          // closing the ResultSet
          try {
              if (result != null)
                  result.close();
          } catch (SQLException e) {
          }
      }
  }
  
  public User getUser(int id) {
      ResultSet result = null;
      try {
          // executing query for user:
          // SELECT * FROM User WHERE ID=id
          result = statement.executeQuery(generateSelect(tUser.tableName,
                  "*", tUser.id, String.valueOf(id)));
          if (!result.first())
              return null;
          // new user is constructed (ID, username, email, password)
          User usr = new user(result.getInt(1), result.getString(2),
                  result.getString(3), result.getString(4));
          return usr;
      } catch (SQLException e) {
          e.printStackTrace();
          return null;
      } catch (BadAttributeValueExpException e) {
          e.printStackTrace();
          return null;
      } finally {
          // closing the ResultSet
          try {
              if (result != null)
                  result.close();
          } catch (SQLException e) {
          }
      }
  }
  
  /* End of class */
  </code></pre>
  
  <p>Statements from both classes are added in constructor, calling connection.getStatement() when constructing each of the classes.</p>
  
  <p>tProject and tProject_User are my enums, I'm using it for easier name handling. generateSelect is my method and should work as expected. I'm using this because I've found out about prepared statements after I have written most of my code, so I left it as it is. </p>
  
  <p>I am using latest java MySQL connector (5.1.21). </p>
  
  <p>I don't know what else to try. Any advice will be appreciated.</p>