Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Tomcat 5.5 JDBC datasource config problem (MySQL)

Reply
Thread Tools

Tomcat 5.5 JDBC datasource config problem (MySQL)

 
 
elektrophyte
Guest
Posts: n/a
 
      01-29-2005
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.create DataSource(BasicDataSource.java:780)
at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.getCon nection(BasicDataSource.java:540)
at gov.mtc.webproc.RequestManager.doPost(RequestManag er.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.in ternalDoFilter(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();
}

 
Reply With Quote
 
 
 
 
Andreas Wollschlaeger
Guest
Posts: n/a
 
      01-29-2005
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

 
Reply With Quote
 
 
 
 
elektrophyte
Guest
Posts: n/a
 
      01-30-2005
Thanks for the reply. I tried adding the DataSource config to an
application-specific context, but the result was the same.

 
Reply With Quote
 
Daniel Rohe
Guest
Posts: n/a
 
      01-30-2005
The configuration of a resource has changed from tomcat 5.0 to 5.5, so
please read the docs

greetings
Daniel

"elektrophyte" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed) oups.com...
> 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.create DataSource(BasicDataSource.java:780)
> at
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.getCon nection(BasicDataSource.java:540)
> at gov.mtc.webproc.RequestManager.doPost(RequestManag er.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.in ternalDoFilter(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();
> }
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
stand-alone JMS, other JDBC operations, and transactions ( ActiveMQ + JOTM + JDBC operations ) Jesus M. Salvo Jr. Java 2 02-11-2006 06:33 PM
Re: Tomcat DataSource config issue Daniel Rohe Java 2 01-13-2006 03:35 PM
Tomcat JDBC setup: DataSource invalid: "java.lang.NullPointerException" cwang66@gmail.com Java 7 10-14-2005 12:45 AM
oracle.jdbc.OracleDriver vs oracle.jdbc.driver.OracleDriver Betty Java 1 05-21-2005 05:15 PM
Re: jdbc help:sun.jdbc.odbc.JdbcOdbcDriver Keith Wansbrough Java 0 08-16-2004 07:31 PM



Advertisments