title: Tomcat with mysql : " Cannot create JDBC driver of class '' for connect URL 'null' "
body: <p>This question has been asked and answered multiple times but it still doesn't solve my problem.</p>
  
  <p>Host OS is Fedora 17</p>
  
  <p>Tomcat package tomcat-7.0.27-2.fc17.noarch</p>
  
  <p>Here is my $CATALINA_HOME/logs/catalina.out</p>
  
  <pre><code>[DEBUG]: Failed to establish connection with datastore
  org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
  ...
  ...
  Caused by: java.sql.SQLException: No suitable driver
      at java.sql.DriverManager.getDriver(DriverManager.java:289)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
  ...
  </code></pre>
  
  <p>Here is my $CATALINA_HOME/conf/Catalina/localhost/ABC/ABC.xml</p>
  
  <pre><code>&lt;Context path="/ABC"&gt;
  
  &lt;!-- maxActive: Maximum number of dB connections in pool. Make sure you
       configure your mysqld max_connections large enough to handle
       all of your db connections. Set to -1 for no limit.
       --&gt;
  
  &lt;!-- maxIdle: Maximum number of idle dB connections to retain in pool.
       Set to -1 for no limit.  See also the DBCP documentation on this
       and the minEvictableIdleTimeMillis configuration parameter.
       --&gt;
  
  &lt;!-- maxWait: Maximum time to wait for a dB connection to become available
       in ms, in this example 10 seconds. An Exception is thrown if
       this timeout is exceeded.  Set to -1 to wait indefinitely.
       --&gt;
  
  &lt;!-- username and password: DB username and KeyDB password key (not the password itself)  --&gt;
  
  &lt;!-- driverClassName: Class name for the JDBC KeyDB wrappers.  These wrappers
       replace the 'mysql_keydb_key' with its corresponding value from KeyDB
       --&gt;
  
  &lt;!-- url: The JDBC connection url for connecting to your MySQL dB.
       The autoReconnect=true argument to the url makes sure that the
       mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
       connection.  mysqld by default closes idle connections after 8 hours.
       --&gt;
  
  &lt;Resource name="jdbc/last_db" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="****" password="****" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/last_db"/&gt;
  &lt;/Context&gt;
  </code></pre>
  
  <p>Here is my $CATALINA_HOME/lib directory</p>
  
  <pre><code>$ ls /usr/share/tomcat/lib
  annotations-api.jar      commons-collections.jar    log4j.jar                          tomcat-i18n-es.jar      tomcat-servlet-3.0-api.jar
  apache-commons-dbcp.jar  commons-dbcp.jar           mysql-connector-java-5.1.0.jar  tomcat-i18n-fr.jar      tomcat-util.jar
  catalina-ant.jar         commons-logging-1.1.1.jar  tomcat-api.jar                  tomcat-i18n-ja.jar
  catalina-ha.jar          jasper-el.jar              tomcat-coyote.jar               tomcat-jdbc.jar
  catalina.jar             jasper.jar                 tomcat-dbcp.jar                 tomcat-jsp-2.2-api.jar
  catalina-tribes.jar      jasper-jdt.jar             tomcat-el-2.2-api.jar           tomcat-juli.jar
  </code></pre>
  
  <p>Here is my WEB-INF/web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  version="2.5"&gt;
  
  &lt;servlet&gt;
      &lt;servlet-name&gt;jersey&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.sun.jersey.spi.container.servlet.ServletContainer&lt;/servlet-class&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;jersey&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/v1/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  &lt;resource-ref&gt;
      &lt;description&gt;DB Connection&lt;/description&gt;
      &lt;res-ref-name&gt;jdbc/last_db&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>Executing code:</p>
  
  <pre><code>try {
      Context initContext = new InitialContext();
      Context envContext  = (Context)initContext.lookup("java:/comp/env");
      dataSource = (DataSource) envContext.lookup("jdbc/"+dbName);
   } catch (NamingException ex) {
      System.out.println("[DEBUG]: Failed to initiate JDBC context");
      ex.printStackTrace();
      return;
   }
  
   try {
       connection = dataSource.getConnection();
   } catch (SQLException ex){
       System.out.println("[DEBUG]: Failed to establish connection with datastore");
       ex.printStackTrace();
       return;
   } catch (ClassNotFoundException ww){
       ww.printStackTrace();
   }
  </code></pre>
  
  <p>The mysql-connector jar seems to be available in WEB-INF/lib</p>
  
  <pre><code>$ jar tf ABC.war | grep mysql-connector
  WEB-INF/lib/mysql-connector-java-5.1.0.jar
  </code></pre>
  
  <p>I don't know if this is useful or not but here is the listening port information for port 3306</p>
  
  <pre><code>$ netstat -tln
  Active Internet connections (only servers)
  Proto Recv-Q Send-Q Local Address           Foreign Address         State      
  tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN     
  </code></pre>