title: Tomcat 8 - java.sql.SQLException: Cannot create JDBC driver of class '' for connect URL 'jdbc:mysql://xxx/myApp'
body: <p>I looked everywhere on the web in order to find a solution to my problem, but I had no luck! :(</p>
  
  <p>I'm trying to develop a servlet able to connect to a MySQL database (Connection Pool) and to deploy it on a Tomcat 8 server.</p>
  
  <p>I have a context.xml file in META-INF like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
     &lt;Context antiJARLocking="true" path="/DBConnectionPoolTest"&gt;
         &lt;Resource name="jdbc/testdb"
                   auth="Container"
                   type="javax.sql.DataSource"
                   username="xxx" password="xxx"
                   driverclassname="com.mysql.jdbc.Driver"
                   url="jdbc:mysql://xxx/myApp"
                   maxactive="10"
                   maxidle="4" /&gt;
     &lt;/Context&gt;
  </code></pre>
  
  <p>In WEB-INF I created the web.xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"&gt;   
      &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;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>Finally, on the servlet class, I use:</p>
  
  <pre><code>Context initContext = new InitialContext();
  Context envContext = (Context) initContext.lookup("java:/comp/env");
  dataSource = (DataSource) envContext.lookup("jdbc/testdb");
  ...
  connection = dataSource.getConnection();
  </code></pre>
  
  <p>But on this line, when I try to get a connection from the datasource, I get the following exception:</p>
  
  <pre><code>java.sql.SQLException: Cannot create JDBC driver of class '' for connect URL 'jdbc:mysql://xxx/myApp'
  t org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2065)
      at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:1939)
      at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1412)
      at DBPoolConnectionServlet.processRequest(DBPoolConnectionServlet.java:73)
  ...
  Caused by: java.sql.SQLException: No suitable driver
  </code></pre>
  
  <p>I thought it could be caused by the absence of the JDBC Driver, so I putted <code>mysql-connector-java-5.1.34-bin.jar</code> in:</p>
  
  <ol>
  <li>pom.xml dependency</li>
  <li>Tomcat LIB folder</li>
  <li>WEB-INF/lib folder inside the webapp</li>
  </ol>
  
  <p>but without luck.</p>
  
  <p>Can you please tell me what I'm doing wrong? I feel so noob... :(</p>
  
  <p>Thank you very much for your time spent reading (and hopefully answering) my question!!!</p>