title: MySQL and JDBC Connection Pool: unclosed statements
body: <p>I am reviewing a big pile of existing code, trying to find unclosed connections that would cause the connection pool to run out or throw other erros.</p>
  
  <p>In some places I see the connection is returned to the pool, the ResultSet is closed, but the PreparedStatement is not closed.</p>
  
  <p>in pseudo code it would look like this:</p>
  
  <pre><code>Connection conn = null;
  try {
     conn = MyJdbcTemplateHolder.getNewConnectionFromPool();
     PreparedStatement ps = conn.prepareStatement(sql, ...);
     ResultSet rs = st.executeQuery();
  
     // do stuff with results
  
  } catch(Exception e) {
     // exception
  } finally {
     rs.close();
     MyJdbcTemplateHolder.returnConnectionToPool(conn);
     //***** Here is what's missing: st.close(); *****
  }
  </code></pre>
  
  <p>The question is: <strong>can the open statement cause issues because it wasn't explicitly closed?</strong> Or is closing the ResultSet and returning the connection enough?</p>
  
  <p>Obviously I am not talking about one open statement - we have a pool of 100 connections and dozens of places in the code where this issue may come up.</p>
  
  <ul>
  <li>MySQL version is 5.1 </li>
  <li>My JDBC jar is <em>mysql-connector-java-5.1.11-bin.jar</em></li>
  </ul>