title: java.sql.sqlexception closed connection next
body: <p><a href="https://i.stack.imgur.com/fYvww.png" rel="nofollow noreferrer">error image</a></p>
  
  <blockquote>
    <p>java.sql.SQLException: Closed Connection: next</p>
    
    <p>at
        oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
        at
        oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
        at
        oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java:181)
        at
        com.mchange.v2.c3p0.impl.NewProxyResultSet.next(NewProxyResultSet.java:2859)</p>
  </blockquote>
  
  <p><strong>Code</strong></p>
  
  <pre><code>if (rs != null) {
      while (rs.next()) {
          resultset = Stmt.executeQuery();
          if (resultset.next()) {
              count += resultset.getLong(1);
              resultset.close();
              resultset = null;
          }
          Stmt.close();
          Stmt = null;
      }
  }
  </code></pre>