title: Operation not allowed after ResultSet closed on javasql exception
body: <p>i am creating simple rest api using jersey and here i assigned all the data fetched from database to variables and then return those variables data as list but i get an error. i have seen other examples but i don't get it whats wrong here is what i did:</p>
  
  <pre><code>public class UserDAOImpl implements UserDAO{
  public List&lt;User&gt; readUser() {
      List&lt;User&gt; list = new ArrayList();
      User u = new User();
      try {
      System.out.println("inside readuser impl");
          Class.forName("com.mysql.jdbc.Driver");
          Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/userdb", "root", "");
          Statement stmt = con.createStatement();
          ResultSet rs = stmt.executeQuery("select * from user");
          while (rs.next()) {
              int id = rs.getInt("id");
              String name = rs.getString("name");
              String address = rs.getString("address");
              u.setId(id);
              u.setName(name);
              u.setAddress(address);
              System.out.println(u);
              list.add(u); //adding user object to list
              con.close();
          }
      } catch (Exception e) {
          System.out.println(e);
      }
      return list; //returning to list for json response
   }
  }
  </code></pre>
  
  <p>and here is my controller that gives json response after getting object</p>
  
  <pre><code>@Path("/rest")
  public class UserController {
  
  @GET
  @Path("/getall")
  @Produces(MediaType.APPLICATION_JSON)
  public List&lt;User&gt; getAllUser(){
      UserDAO udao = new UserDAOImpl();
  
      return udao.readUser();
   }
  
  }
  </code></pre>