title: Tomcat7 JDBC pools
body: <p>I have the following in META-INF</p>
  
  <pre><code>&lt;Context&gt;
     &lt;Resource type="javax.sql.DataSource"
          name="jdbc/TestDB"
          factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
          driverClassName="com.mysql.jdbc.Driver"
          url="jdbc:mysql://localhost:3306/"
          username="mysql_user"
          password="mypassword123"/&gt;
  &lt;/Context&gt;
  </code></pre>
  
  <p>In my web.xml I have </p>
  
  <pre><code>&lt;resource-ref&gt;
    &lt;description&gt;DB Connection&lt;/description&gt;
    &lt;res-ref-name&gt;jdbc/TestDB&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>In my Java code I have </p>
  
  <pre><code>Context initContext = new InitialContext();
  Context envContext  = (Context)initContext.lookup("java:/comp/env");
  DataSource datasource = (DataSource)envContext.lookup("jdbc/TestDB");
  con = datasource.getConnection();
  </code></pre>
  
  <p>When Tomcat is starting up I get the following error and I have mysql-connector-java-5.1.20-bin.jar in my libs folder. Any idea why?</p>
  
  <pre><code>INFO: Starting Servlet Engine: Apache Tomcat/7.0.27
  05-Jun-2012 23:16:29 org.apache.naming.NamingContext lookup
  WARNING: Unexpected exception resolving reference
  java.sql.SQLException: com.mysql.jdbc.Driver
  at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:242)
  at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:175)
  at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:684)
  at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:616)
  at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:479)
  at org.apache.tomcat.jdbc.pool.ConnectionPool.&lt;init&gt;(ConnectionPool.java:135)
  at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:114)
  at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:101)
  at org.apache.tomcat.jdbc.pool.DataSourceFactory.createDataSource(DataSourceFactory.java:501)
  at org.apache.tomcat.jdbc.pool.DataSourceFactory.getObjectInstance(DataSourceFactory.java:224)
  at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:143)
  at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
  at org.apache.naming.NamingContext.lookup(NamingContext.java:843)
  at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
  at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
  at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
  at org.apache.catalina.core.NamingContextListener.addResource(NamingContextListener.java:1061)
  at org.apache.catalina.core.NamingContextListener.createNamingContext(NamingContextListener.java:671)
  at org.apache.catalina.core.NamingContextListener.lifecycleEvent(NamingContextListener.java:270)
  at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
  at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
  at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5161)
  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
  at java.util.concurrent.FutureTask.run(FutureTask.java:138)
  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
  at java.lang.Thread.run(Thread.java:662)
  Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
  at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
  at java.lang.Class.forName0(Native Method)
  at java.lang.Class.forName(Class.java:247)
  at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:235)
  ... 29 more
  </code></pre>