title: MaxOpenPreparedStatements limit reached
body: <p>I get this exception only for SOME database update in my code after several days of application running. Some of the requests passed, and some of them (the same java code) fail.</p>
  
  <pre><code>java.sql.SQLException: MaxOpenPreparedStatements limit reached
         at org.apache.commons.dbcp.PoolingConnection.prepareStatement(PoolingConnection.java:109)
         at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:281)
         at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:313)
         at com.prog.C.f(C.java:967)
         at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
         at java.lang.Thread.run(Thread.java:619)
  Caused by: java.util.NoSuchElementException
         at org.apache.commons.pool.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:808)
         at org.apache.commons.dbcp.PoolingConnection.prepareStatement(PoolingConnection.java:107)
         ... 15 more
  </code></pre>
  
  <p>Datasource config:</p>
  
  <pre><code>&lt;bean id="DataSource" class="org.apache.commons.dbcp.BasicDataSource"
            destroy-method="close" lazy-init="true" scope="singleton"&gt;
          &lt;property name="driverClassName" value="${jdbc.driver.class}"/&gt;
          &lt;property name="url" value="${jdbc.url}"/&gt;
          &lt;property name="username" value="${jdbc.username}"/&gt;
          &lt;property name="password" value="${jdbc.password}"/&gt;
          &lt;property name="poolPreparedStatements" value="true"/&gt;
          &lt;property name="maxOpenPreparedStatements" value="20"/&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>There are allways available connections. How can I fix it? Thanks.</p>