title: Tomcat Connection Pool configuration: DataSource type and "Too many connection" error
body: <p>I'm using the tomcat connection pool via JNDI resources.</p>
  
  <p>In the <code>context.xml</code>:</p>
  
  <pre><code>&lt;Resource name="jdbc/mydb" auth="Container" type="javax.sql.DataSource"
            username="root" password="root" driverClassName="com.mysql.jdbc.Driver"
            maxActive="1000" maxIdle="100" maxWait="10000"
            url="jdbc:mysql://localhost:3306/mydatabase" 
            factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" /&gt;
  </code></pre>
  
  <p>In <code>web.xml</code>:</p>
  
  <pre><code>&lt;resource-ref&gt;
  &lt;description&gt;DB Connection&lt;/description&gt;
  &lt;res-ref-name&gt;jdbc/mydb&lt;/res-ref-name&gt;
  &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
  &lt;res-auth&gt;Container&lt;/res-auth&gt;
  &lt;/resource-ref&gt;
  </code></pre>
  
  <p>From the java classes in which I need db connections, I do this lookup:</p>
  
  <pre><code>Context initContext = new InitialContext();
  DataSource ds = (DataSource)initContext.lookup("java:/comp/env/jdbc/mydb");
  </code></pre>
  
  <p>My first doubt is the DataSource type. Is it the same using <code>javax.sql.DataSource</code> or <code>org.apache.tomcat.jdbc.pool.DataSource</code>?</p>
  
  <p>Moreover, sometimes I obtain a "Too many connections" error.
  I've read many stackoverflow question/answers about this, but I don't succeed in understanding where the problem could be.</p>
  
  <p>I have followed the tomcat docs, and I close properly result sets, statements and connection.  </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>My tomcat version is 7.0.26. So there should be a bug (see link suggested by informatik01 user)</p>