title: SQLException: No suitable driver found
body: <p>I have a Java class that accesses a MySQL database through JDBC that I use in a JSP running on Tomcat, and I am getting No Driver Found Exception.</p>
  
  <p>I have a method:</p>
  
  <pre><code>private static Statement makeStatement() {
     try{
      com.mysql.jdbc.Driver d = null;
      try{d = new com.mysql.jdbc.Driver();}catch(Exception e){
        System.out.println("ERROR BY NEW DRIVER " + e.toString() + 
        "\n");e.printStackTrace();}
      Connection con = DriverManager.getConnection(url, user, password);
      return con.createStatement();
     }catch(java.sql.SQLException ex){
        System.out.println("ERROR IN makeStatement " + "\nERROR - " +
        ex.toString() +  "\n ERROR CODE:\n " + ex.getErrorCode() + 
        "\nSQLSTATE:\n " + ex.getSQLStat        e());ex.printStackTrace();}
      return null;
   }
  </code></pre>
  
  <p>That throws an error at <code>Connection con = DriverManager.getConnection(url, user, password);</code> Here is my printout from catalina.out:</p>
  
  <pre><code>  Received Parameters
  
  ERROR IN makeStatement 
  ERROR - java.sql.SQLException: No suitable driver found for 
   ERROR CODE:
   0
  SQLSTATE:
   08001
  java.sql.SQLException: No suitable driver found for 
          at java.sql.DriverManager.getConnection(DriverManager.java:602)
          at java.sql.DriverManager.getConnection(DriverManager.java:185)
          at message.Message.makeStatement(Message.java:72)
          at message.Message.query(Message.java:79)
          at message.Message.getName(Message.java:225)
          at org.apache.jsp.message_jsp._jspService(message_jsp.java:288)
          at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
          at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
          at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
          at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
          at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:548)
          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
          at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
          at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
          at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
          at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
          at java.lang.Thread.run(Thread.java:619)
  ERROR IN QUERY java.lang.NullPointerException
  ERROR in getName java.lang.NullPointerException
  -----------------------------------
  
    Received Parameters
  
          newMessage      =  
          newpassword     = 
          verifypassword  = 
          sendinfo        = 
          username        = Eli
          newusername     = 
          login   = login
          password        = tree
  ERROR IN makeStatement 
  ERROR - java.sql.SQLException: No suitable driver found for 
   ERROR CODE:
   0
  SQLSTATE:
   08001
  java.sql.SQLException: No suitable driver found for 
          at java.sql.DriverManager.getConnection(DriverManager.java:602)
          at java.sql.DriverManager.getConnection(DriverManager.java:185)
          at message.Message.makeStatement(Message.java:72)
          at message.Message.query(Message.java:79)
          at message.Message.validUser(Message.java:195)
          at org.apache.jsp.message_jsp._jspService(message_jsp.java:123)
          at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
          at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
          at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
          at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
          at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:548)
          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
          at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
          at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
          at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
          at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
          at java.lang.Thread.run(Thread.java:619)
  ERROR IN QUERY java.lang.NullPointerException
  ERROR in validUser java.lang.NullPointerException
  ERROR IN makeStatement 
  ERROR - java.sql.SQLException: No suitable driver found for 
   ERROR CODE:
   0
  SQLSTATE:
   08001
  java.sql.SQLException: No suitable driver found for 
          at java.sql.DriverManager.getConnection(DriverManager.java:602)
          at java.sql.DriverManager.getConnection(DriverManager.java:185)
          at message.Message.makeStatement(Message.java:72)
          at message.Message.query(Message.java:79)
          at message.Message.getName(Message.java:225)
          at org.apache.jsp.message_jsp._jspService(message_jsp.java:288)
          at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
          at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
          at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
          at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
          at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:548)
          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
          at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
          at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
          at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
          at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
          at java.lang.Thread.run(Thread.java:619)
  ERROR IN QUERY java.lang.NullPointerException
  ERROR in getName java.lang.NullPointerException
  </code></pre>
  
  <p>The only error that matters is the one in <code>makeStatement()</code> as that failing causes all the other errors. I have quadruple checked that I have the correct jar files in my WEB-INF/lib directory and I have restarted Tomcat more times than I would ever want to. I have a separate webapp that uses <code>makeStatement()</code> in a different .java file, and that webapp runs fine. Even weirder is that I have this in the .java:</p>
  
  <pre><code>static {
    System.err.println("\n\nTEST MYSQL ACCESS: dump all relevant tables:");
    dump();
    System.err.println("END OF MYSQL ACCESS ACCESS.");
  }
  
   public static void dump() {
     try {
       readUsers();
       for (UserRecord u: users)
       System.err.println(u.username+" "+u.password);
     } catch (Exception e) {System.err.println(e);}
   }
  </code></pre>
  
  <p>where <code>readUsers()</code> reads all the users from the database using <code>makeStatement()</code>. This actually works and all the users in the database are printed (not shown here for obvious reasons :) ) and then the driver not found error occurs.</p>