title: DBCP Connection Pool leak : Connection.close() don't return the Connection to the pool and the connection is exhausted
body: <p>DBCP connection pool leak .</p>
  
  <p>When the program return the connection used, the connection resource is not returned to 
   the pool and is exhausted !!!</p>
  
  <p>So, in maxActive time Connection.close(), the pool hangs when getConnection().</p>
  
  <p>Please let me know how to solve this problem !!!</p>
  
  <p>library :</p>
  
  <p>commons-dbcp-1.4.jar
  commons-pool-1.6.jar
  mysql-connector-java-5.1.12.jar</p>
  
  <p>Mysql version : 5.5.9</p>
  
  <p>Sources :</p>
  
  <pre><code>import java.sql.Connection;
  import java.sql.Driver;
  import java.sql.DriverManager;
  
  
  
  class ConnectionManager {
  
      static {
  
          java.sql.DriverManager.registerDriver((java.sql.Driver) 
                    Class.forName("org.apache.commons.dbcp.PoolingDriver").newInstance()) ;
          java.sql.DriverManager.registerDriver((java.sql.Driver) 
                    Class.forName("com.mysql.jdbc.Driver").newInstance()) ;
     }
  
     public Connection getConnection(String dataSourceName) {
  
         return DriverManager.getConnection("jdbc:apache:commons:dbcp:/"+dataSourceName);
     }
  
  }
  </code></pre>
  
  <p>query source ::</p>
  
  <pre><code>String dsName = "pool" ;
  
  ConnectionManager pool = new ConnectionManager();
  
  java.sql.Connection conn = pool.getConnection(dsName);
  
  
  conn.setAutoCommit(true);
  if( m_sql.trim().toUpperCase().startsWith("INSERT") )
      pstmt = conn.prepareStatement(m_sql, Statement.RETURN_GENERATED_KEYS);
  else
      pstmt = conn.prepareStatement(m_sql);
  
  pstmt.setFetchSize(100);
  
  boolean hasRS = pstmt.execute();
  
  ResultSet resSet = null ;
  
  if (hasRS) {
     resSet = pstmt.getResultSet();
  
  } else {
     resSet = null;
     return ;
  }
  
  while(resSet.next()) {
  
       //resultSet processing ....
       ::::::
  }
  
  
  resSet.close() ;
  pstmt.close() ;
  conn.close() ;  --&gt; don't return the connection to the pool and exhaust the connection...;;;
  </code></pre>
  
  <p>:::</p>
  
  <p>poo.jocl  :: this is located in $CLASSPATH</p>
  
  <p></p>
  
  <pre><code>&lt;object class="org.apache.commons.dbcp.DriverManagerConnectionFactory"&gt;
      &lt;string value="jdbc:mysql://localhost:3306/db?useUnicode=true&amp;amp;traceProtocol=true&amp;amp;characterEncoding=UTF-8"/&gt;
      &lt;string value="usera"/&gt;
      &lt;string value="passa"/&gt;
  &lt;/object&gt;
  
  &lt;object class="org.apache.commons.pool.impl.GenericObjectPool"&gt;
      &lt;object class="org.apache.commons.pool.PoolableObjectFactory" null="true" /&gt;
      &lt;int value="100" /&gt; &lt;!-- maxActive --&gt;
              &lt;byte value="1" /&gt; &lt;!-- whenExhaustedAction --&gt;
      &lt;long value="10000" /&gt; &lt;!-- maxWait --&gt;
      &lt;int value="30" /&gt; &lt;!-- maxIdle --&gt;
      &lt;int value="3" /&gt;  &lt;!-- minIdle --&gt;
      &lt;boolean value="true" /&gt; &lt;!-- testOnBorrow --&gt;
      &lt;boolean value="true" /&gt;  &lt;!--testOnReturn --&gt;
      &lt;long value="600000" /&gt;  &lt;!-- timeBetweenEvictionRunsMillis --&gt;
      &lt;int value="5" /&gt;  &lt;!-- numTestsPerEvictionRun --&gt;
      &lt;long value="3600000" /&gt; &lt;!-- minEvictableIdleTimeMillis --&gt;
      &lt;boolean value="true" /&gt; &lt;!-- testWhileIdle --&gt;
  &lt;/object&gt;
  
  &lt;object class="org.apache.commons.pool.KeyedObjectPoolFactory" null="true"/&gt;    
  &lt;string null="true"/&gt;   
  &lt;boolean value="false"/&gt;
  &lt;boolean value="true"/&gt;
  </code></pre>
  
  <p></p>