title: SEVERE: Unable to create initial connections of pool - tomcat 7 with context.xml file
body: <p>I tried to run project on tomcat <code>7.0.52</code> and initialize to DB through <code>context.xml</code> file.</p>
  
  <p>But it throws bunch of exceptions, I couldn't figure out what is wrong there.</p>
  
  <p>Here is console output:</p>
  
  <pre><code>java.sql.SQLException: com.mysql.jdbc.Driver
      at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:254)
      at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:182)
      at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:701)
      at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:635)
      at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:486)
      at org.apache.tomcat.jdbc.pool.ConnectionPool.&lt;init&gt;(ConnectionPool.java:144)
      at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:116)
      at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:103)
      at org.apache.tomcat.jdbc.pool.DataSourceFactory.createDataSource(DataSourceFactory.java:554)
      at org.apache.tomcat.jdbc.pool.DataSourceFactory.getObjectInstance(DataSourceFactory.java:242)
      at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:141)
      at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
  </code></pre>
  
  <p>Here is full <a href="http://pastebin.com/YxdqUySS" rel="noreferrer">stack trace</a>.</p>
  
  <p>Here is output to <a href="http://pastebin.com/HqNag3tA" rel="noreferrer">tomcat catalina log</a></p>
  
  <p>snippet of <strong>web.xml</strong>:</p>
  
  <pre><code>&lt;resource-ref&gt;
      &lt;description&gt;Travel Agency Datasource&lt;/description&gt;
      &lt;res-ref-name&gt;jdbc/onlinedb&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><strong>context.xml</strong>:</p>
  
  <pre><code>&lt;Context&gt;
      &lt;Resource name="jdbc/onlinedb"
                type="javax.sql.DataSource"
                factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
                maxActive="20" maxIdle="10"
                maxWait="-1"
                username="root"
                password="secret"
                driverClassName="com.mysql.jdbc.Driver"
                url="jdbc:mysql://localhost:3306/travelagency?characterEncoding=utf8"/&gt;
  &lt;/Context&gt;
  </code></pre>
  
  <p><strong>ConnectionManager</strong> class:</p>
  
  <pre><code>public class ConnectionManager {
      private static Logger log = Logger.getLogger(ConnectionManager.class);
  
      public static Connection getConnection() throws SQLException {
          Connection con = null;
          try {
              Context initContext = new InitialContext();
              Context envContext = (Context) initContext.lookup("java:/comp/env");
              DataSource datasource = (DataSource) envContext.lookup("jdbc/onlinedb");
              con = datasource.getConnection();
          } catch (NamingException e) {
              log.error(e);
          }
          return con;
      }
  }
  </code></pre>
  
  <p><code>mysql-connector-java-5.1.27-bin.jar</code> is added to cp:</p>
  
  <p><img src="https://i.stack.imgur.com/4cHST.png" alt="travel"></p>
  
  <p>I tried to change content of context.xml file:</p>
  
  <pre><code>&lt;resource-env-ref&gt;
          &lt;description&gt;Travel Agency Datasource&lt;/description&gt;
          &lt;resource-env-ref-name&gt;jdbc/onlinedb&lt;/resource-env-ref-name&gt;
          &lt;resource-env-ref-type&gt;javax.sql.DataSource&lt;/resource-env-ref-type&gt;
  &lt;/resource-env-ref&gt;
  </code></pre>
  
  <p>But it keep failing.</p>
  
  <p><strong><em>How to solve this trouble?</em></strong></p>