Tomcat 5.5 JDBC datasource config problem (MySQL)

Discussion in 'Java' started by elektrophyte, Jan 29, 2005.

  1. elektrophyte

    elektrophyte Guest

    Hi folks. Any help with this problem would be greatly appreciated. I'm
    trying to set up Tomcat 5.5 to provide a JNDI DataSource of a MySQL
    4.0.22 server on Windows XP. Configuration details are below. When I
    step through the code in the debugger, it appears that the DataSource
    object is sucessfully created. At least it isn't null. However, when
    it gets to the line...

    Connection con = dataSource.getConnection();

    .... it throws this exception:

    org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC
    driver of class '' for connect URL 'null'
    at
    org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:780)
    at
    org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
    at gov.mtc.webproc.RequestManager.doPost(RequestManager.java:65)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    at
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
    etc...

    ------------------------------------------------------------------

    Some more details:

    - I put the driver (mysql-connector-java-3.1.6-bin.jar) into
    TOMCAT_HOME/common/lib/.

    - In server.xml, inside <Host name="localhost" ... > ... </Host> I put
    this configuration:

    <DefaultContext>
    <Resource name="jdbc/commutercorpsds" auth="Container"
    type="javax.sql.DataSource"/>
    <ResourceParams name="jdbc/commutercorpsds">
    <parameter>
    <name>driverClassName</name>
    <value>com.mysql.jdbc.Driver</value>
    </parameter>
    <parameter>
    <name>url</name>
    <value>jdbc:mysql://localhost:3306/commuter_corps_signup</value>
    </parameter>
    <parameter>
    <name>username</name>
    <value>USERNAME</value>
    </parameter>
    <parameter>
    <name>password</name>
    <value>PASSWORD</value>
    </parameter>
    <parameter>
    <name>maxActive</name>
    <value>20</value>
    </parameter>
    <parameter>
    <name>maxIdle</name>
    <value>30000</value>
    </parameter>
    <parameter>
    <name>maxWait</name>
    <value>100</value>
    </parameter>
    <parameter>
    <name>removeAbandoned</name>
    <value>true</value>
    </parameter>
    <parameter>
    <name>removeAbandonedTimeout</name>
    <value>15</value>
    </parameter>
    </ResourceParams>
    </DefaultContext>

    - In my application's web.xml I put this:

    <resource-ref>
    <res-ref-name>jdbc/commutercorpsds</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>

    - In my Java code I put this:

    try
    {
    InitialContext initialContext = new
    InitialContext();
    DataSource dataSource =
    (DataSource) initialContext.lookup
    ("java:comp/env/jdbc/commutercorpsds");
    Connection con = dataSource.getConnection();
    Statement stmt = con.createStatement();

    ....

    con.close();
    stmt.close();
    } catch (NamingException e)
    {
    System.out.println(e.getMessage());
    e.printStackTrace();
    }
    elektrophyte, Jan 29, 2005
    #1
    1. Advertising

  2. elektrophyte wrote:
    > Hi folks. Any help with this problem would be greatly appreciated. I'm
    > trying to set up Tomcat 5.5 to provide a JNDI DataSource of a MySQL
    > 4.0.22 server on Windows XP. Configuration details are below. When I
    > step through the code in the debugger, it appears that the DataSource
    > object is sucessfully created. At least it isn't null. However, when
    > it gets to the line...
    >
    > Connection con = dataSource.getConnection();
    >
    > ... it throws this exception:
    >
    > org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC
    > driver of class '' for connect URL 'null'
    > at
    >
    > <DefaultContext>
    > <Resource name="jdbc/commutercorpsds" auth="Container"
    > type="javax.sql.DataSource"/>
    > <ResourceParams name="jdbc/commutercorpsds">
    > <parameter>
    > <name>driverClassName</name>
    > <value>com.mysql.jdbc.Driver</value>
    > </parameter>
    > <parameter>
    > <name>url</name>
    > <value>jdbc:mysql://localhost:3306/commuter_corps_signup</value>
    > </parameter>
    > <parameter>
    > <name>username</name>
    > <value>USERNAME</value>
    > </parameter>
    > <parameter>
    > <name>password</name>
    > <value>PASSWORD</value>
    > </parameter>
    > <parameter>
    > <name>maxActive</name>
    > <value>20</value>
    > </parameter>
    > <parameter>
    > <name>maxIdle</name>
    > <value>30000</value>
    > </parameter>
    > <parameter>
    > <name>maxWait</name>
    > <value>100</value>
    > </parameter>
    > <parameter>
    > <name>removeAbandoned</name>
    > <value>true</value>
    > </parameter>
    > <parameter>
    > <name>removeAbandonedTimeout</name>
    > <value>15</value>
    > </parameter>
    > </ResourceParams>
    > </DefaultContext>
    >


    I remember i had this kind of problem with Tomcat 4.0.6 some decade ago
    - try moving the configuration of the Datasource from the DefaultContext
    to a more specific context. Some neurons say this was a problem with
    Tomcat 4, so i'm surprised this still happens with Tomcat 5.5 - as the
    DefaultContext is the most natural place. Maybe have a look
    jakarta.apache.org, i think it was somewhere in the FAQs.

    HTH, though :)
    Andreas
    Andreas Wollschlaeger, Jan 29, 2005
    #2
    1. Advertising

  3. elektrophyte

    elektrophyte Guest

    Thanks for the reply. I tried adding the DataSource config to an
    application-specific context, but the result was the same.
    elektrophyte, Jan 30, 2005
    #3
  4. elektrophyte

    Daniel Rohe Guest

    The configuration of a resource has changed from tomcat 5.0 to 5.5, so
    please read the docs

    greetings
    Daniel

    "elektrophyte" <> schrieb im Newsbeitrag
    news:...
    > Hi folks. Any help with this problem would be greatly appreciated. I'm
    > trying to set up Tomcat 5.5 to provide a JNDI DataSource of a MySQL
    > 4.0.22 server on Windows XP. Configuration details are below. When I
    > step through the code in the debugger, it appears that the DataSource
    > object is sucessfully created. At least it isn't null. However, when
    > it gets to the line...
    >
    > Connection con = dataSource.getConnection();
    >
    > ... it throws this exception:
    >
    > org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC
    > driver of class '' for connect URL 'null'
    > at
    > org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:780)
    > at
    > org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
    > at gov.mtc.webproc.RequestManager.doPost(RequestManager.java:65)
    > at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    > at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    > at
    > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
    > etc...
    >
    > ------------------------------------------------------------------
    >
    > Some more details:
    >
    > - I put the driver (mysql-connector-java-3.1.6-bin.jar) into
    > TOMCAT_HOME/common/lib/.
    >
    > - In server.xml, inside <Host name="localhost" ... > ... </Host> I put
    > this configuration:
    >
    > <DefaultContext>
    > <Resource name="jdbc/commutercorpsds" auth="Container"
    > type="javax.sql.DataSource"/>
    > <ResourceParams name="jdbc/commutercorpsds">
    > <parameter>
    > <name>driverClassName</name>
    > <value>com.mysql.jdbc.Driver</value>
    > </parameter>
    > <parameter>
    > <name>url</name>
    > <value>jdbc:mysql://localhost:3306/commuter_corps_signup</value>
    > </parameter>
    > <parameter>
    > <name>username</name>
    > <value>USERNAME</value>
    > </parameter>
    > <parameter>
    > <name>password</name>
    > <value>PASSWORD</value>
    > </parameter>
    > <parameter>
    > <name>maxActive</name>
    > <value>20</value>
    > </parameter>
    > <parameter>
    > <name>maxIdle</name>
    > <value>30000</value>
    > </parameter>
    > <parameter>
    > <name>maxWait</name>
    > <value>100</value>
    > </parameter>
    > <parameter>
    > <name>removeAbandoned</name>
    > <value>true</value>
    > </parameter>
    > <parameter>
    > <name>removeAbandonedTimeout</name>
    > <value>15</value>
    > </parameter>
    > </ResourceParams>
    > </DefaultContext>
    >
    > - In my application's web.xml I put this:
    >
    > <resource-ref>
    > <res-ref-name>jdbc/commutercorpsds</res-ref-name>
    > <res-type>javax.sql.DataSource</res-type>
    > <res-auth>Container</res-auth>
    > </resource-ref>
    >
    > - In my Java code I put this:
    >
    > try
    > {
    > InitialContext initialContext = new
    > InitialContext();
    > DataSource dataSource =
    > (DataSource) initialContext.lookup
    > ("java:comp/env/jdbc/commutercorpsds");
    > Connection con = dataSource.getConnection();
    > Statement stmt = con.createStatement();
    >
    > ...
    >
    > con.close();
    > stmt.close();
    > } catch (NamingException e)
    > {
    > System.out.println(e.getMessage());
    > e.printStackTrace();
    > }
    >
    Daniel Rohe, Jan 30, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ck388
    Replies:
    0
    Views:
    3,778
    ck388
    Jun 6, 2003
  2. bigbinc
    Replies:
    0
    Views:
    920
    bigbinc
    Jul 23, 2004
  3. Keith Wansbrough

    Re: jdbc help:sun.jdbc.odbc.JdbcOdbcDriver

    Keith Wansbrough, Aug 16, 2004, in forum: Java
    Replies:
    0
    Views:
    733
    Keith Wansbrough
    Aug 16, 2004
  4. Replies:
    7
    Views:
    7,516
    Anonymous
    Oct 14, 2005
  5. Daniel Rohe

    Re: Tomcat DataSource config issue

    Daniel Rohe, Dec 20, 2005, in forum: Java
    Replies:
    2
    Views:
    612
    MileHighCelt
    Jan 13, 2006
Loading...

Share This Page