File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

No suitable driver

 
Jim Masters
Greenhorn
Posts: 12
Eclipse IDE Java MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using Tomcat 5.0.28, JSDK 1.4.2_08 and MYSQL 5.0.

I get the follow message:

javax.servlet.ServletException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.TryDB_jsp._jspService(TryDB_jsp.java:113)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"
org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.getConnection(QueryTagSupport.java:276)
org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doStartTag(QueryTagSupport.java:159)
org.apache.jsp.TryDB_jsp._jspx_meth_sql_query_0(TryDB_jsp.java:172)
org.apache.jsp.TryDB_jsp._jspService(TryDB_jsp.java:85)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)



Any suggestions?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This sort of exception happens because:
  • Your JDBC URL is wrong
  • The driver classes are not in your classpath

  • Your URL looks OK (though I haven't checked, so you might want to do this yourself) so it looks like the driver is not on the classpath.
     
    Jim Masters
    Greenhorn
    Posts: 12
    Eclipse IDE Java MySQL Database
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    It's in my classpath:

    C:\MySQL\mysql-connector-java-3.1.12\mysql-connector-java-3.1.12-bin.jar
     
    Jim Masters
    Greenhorn
    Posts: 12
    Eclipse IDE Java MySQL Database
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    url="jdbc:mysql://localhost:3306/wroxcatalog"

    Am I right in that the URL should contain the server (localhost), port number (3306) and the name of the database (wroxcatalog)?
     
    Jim Masters
    Greenhorn
    Posts: 12
    Eclipse IDE Java MySQL Database
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I will never understand why this stuff is so difficult.
     
    stu derby
    Ranch Hand
    Posts: 333
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Paul Sturrock:
    This sort of exception happens because:
  • Your JDBC URL is wrong
  • The driver classes are not in your classpath


  • Or, while the driver is in your classpath, nothing has loaded it. (Normally, you should get an exception loading the driver class if the driver class is not in the classpath; I suppose it's possible that the sql tag is eating or hiding your exception, but you should look in your application log...)

    BTW, the application's classpath is not necessarily inherited from an environmental variable. While a standalone Java program inherit from the environment, most IDEs (such as NetBeans and Eclipse) and most J2EE servers will ignore the the environmental variable. For IDEs, the classpath is set as part of the project setup. For J2EE applications, certain locations such as WEB-INF/lib are in the classpath and are the correct locations for driver jars.

    I'd assume that Tomcat follows the J2EE rules, although I've never used it standalone, just with JBoss...
     
    Jim Masters
    Greenhorn
    Posts: 12
    Eclipse IDE Java MySQL Database
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by stu derby:

    Or, while the driver is in your classpath, nothing has loaded it. (Normally, you should get an exception loading the driver class if the driver class is not in the classpath; I suppose it's possible that the sql tag is eating or hiding your exception, but you should look in your application log...)

    BTW, the application's classpath is not necessarily inherited from an environmental variable. While a standalone Java program inherit from the environment, most IDEs (such as NetBeans and Eclipse) and most J2EE servers will ignore the the environmental variable. For IDEs, the classpath is set as part of the project setup. For J2EE applications, certain locations such as WEB-INF/lib are in the classpath and are the correct locations for driver jars.

    I'd assume that Tomcat follows the J2EE rules, although I've never used it standalone, just with JBoss...



    The MYSQL JAR is in my classpath. I'm getting the error when I attempt to acccess the page from Tomcat through the IE browser.
     
    Paul Sturrock
    Bartender
    Posts: 10336
    Eclipse IDE Hibernate Java
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    stu derby has a good point - is your DataSource actually loading the driver? What do the logs say?
     
    Jim Masters
    Greenhorn
    Posts: 12
    Eclipse IDE Java MySQL Database
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    It doesn't seem to be loading to me....this is from the log:

    2006-05-11 16:13:16 StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
    javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"
    at org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.getConnection(QueryTagSupport.java:276)
    at org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doStartTag(QueryTagSupport.java:159)
    at org.apache.jsp.TryDB_jsp._jspx_meth_sql_query_0(TryDB_jsp.java:149)
    at org.apache.jsp.TryDB_jsp._jspService(TryDB_jsp.java:82)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
    at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
    at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
    at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
    at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
    at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
    at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
    at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
    at java.lang.Thread.run(Thread.java:534)
     
    Jim Masters
    Greenhorn
    Posts: 12
    Eclipse IDE Java MySQL Database
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Any more suggestions? I really don't have any more clues as to what this could be...
     
    Ernest Friedman-Hill
    author and iconoclast
    Marshal
    Pie
    Posts: 24204
    34
    Chrome Eclipse IDE Mac OS X
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You've already been given the answer. Tomcat won't load the driver (or any classes) based on the value of the CLASSPATH environment variable; you must install the driver in Tomcat. That means putting it on the Web application's class path: in WEB-INF/lib, in ${CATALINA_HOME}/shared/lib, or in ${CATALINA_HOME}/common/lib. Any place else, and Tomcat won't find it.

    The same goes for any other libraries you use in your web applications.
     
    Jim Masters
    Greenhorn
    Posts: 12
    Eclipse IDE Java MySQL Database
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Ernest Friedman-Hill:
    You've already been given the answer. Tomcat won't load the driver (or any classes) based on the value of the CLASSPATH environment variable; you must install the driver in Tomcat. That means putting it on the Web application's class path: in WEB-INF/lib, in ${CATALINA_HOME}/shared/lib, or in ${CATALINA_HOME}/common/lib. Any place else, and Tomcat won't find it.

    The same goes for any other libraries you use in your web applications.


    I have already tried everything you mention, and I still get the error. So I was asking for any other suggestions, since I am clueless now as to what the problem is.
     
    Paul Clapham
    Sheriff
    Pie
    Posts: 20177
    25
    MySQL Database
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Step 1: make sure that mysql-connector-java-3.1.12-bin.jar contains the JDBC driver.

    Step 2: put it into the WEB-INF/lib folder of your web application.

    Step 3: restart Tomcat.
     
    Jim Masters
    Greenhorn
    Posts: 12
    Eclipse IDE Java MySQL Database
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Paul Clapham:
    Step 1: make sure that mysql-connector-java-3.1.12-bin.jar contains the JDBC driver.

    Step 2: put it into the WEB-INF/lib folder of your web application.

    Step 3: restart Tomcat.


    -------------------------------------------------------------------------
    Here is a list of what I can think of that I have tried and nothing resolves the "no suitable driver" error:
    1) I tried your suggestion above and I still get "no suitable driver".
    2) I have tried putting the MySQL JAR (mysql-connector-java-3.1.12-bin.jar) in WEB-INF/lib, common/lib and shared/lib.
    3) I have tried putting the MySQL JAR ZIP file mysql-connector-java-3.1.12.zip in WEB-INF/lib, common/lib and shared/lib
    4) I have placed "<% Class.forName("com.mysql.jdbc.Driver"); %>
    " in the JSP page.
    5) I changed localhost in the URL connection string to 127.0.0.1.
    6) I added the MySQL server port 3306 to the URL connection string.
    7) I have tried using another MySQL Jar mysql-connector-java-5.0.0-beta-bin.jar.
    8) I have completely uninstalled Tomcat 5.0.28 and reinstalled it.
    9) I have completely uninstalled MySQL and reinstalled it, resetting up the database.
    10) I have triple checked the database priveleges, login ID (wroxuser), password (wrox), table (products).

    Thanks for all the help, and I sincerely mean that.

    I don't know what else to do...I have thought about formatting my hard drive and reinstalling all software, but I don't think that my employer will allow me to do that.

     
    Ernest Friedman-Hill
    author and iconoclast
    Marshal
    Pie
    Posts: 24204
    34
    Chrome Eclipse IDE Mac OS X
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Well, just for yuks, let's see your web.xml file.
     
    Jim Masters
    Greenhorn
    Posts: 12
    Eclipse IDE Java MySQL Database
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

    <web-app>
    <servlet>
    <servlet-name>WroxCatalog</servlet-name>
    <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
    <servlet-name>WroxCatalog</servlet-name>
    <url-pattern>*.htm</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
    <welcome-file>
    index.jsp
    </welcome-file>
    </welcome-file-list>
    </web-app>
     
    Jim Masters
    Greenhorn
    Posts: 12
    Eclipse IDE Java MySQL Database
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I want to thank all of you that helped...I really appreciate the effort.

    You have no idea how much you appreciate the help other people give you until you are completely clueless about how to resolve a problem and you wait with excited atticipation on possible solutions that others offer up.

    I'm giving up on this problem....chucking the book and starting over with another book.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic