tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: MySql Connector returning ?DataSource
Date Mon, 23 Jul 2007 19:43:46 GMT
Hash: SHA1


Prem Padarath wrote:
> I am trying to set up a database resource in Tomcat 5.5.20 .  I am having a
> problem getting a DataSource object back from a JNDI lookup.
> (I am getting a "org.apache.tomcat.dbcp.dbcp.BasicDataSource" object
> returned and throwing an exception - code below)

o.a.t.d.d.BasicDataSource implements javax.sql.DataSource. What's the

> My context.xml file (placed in my webapp under META-INF) looks as follows:
> <Context crossContext="true" path="/dbtest" reloadable="true">

Remove the "path" attribute, please. It is unlikely to be causing
problems, but you should definitely take it out.

>          <Resource
>            name="jdbc/MYSQLDS"
>            auth="Container"
>            type="javax.sql.DataSource"
>            driverClassName="com.mysql.jdbc.Driver"
>            url="jdbc:mysql://localhost:3306/testdb"/>

This looks fine.

> My web.xml file contains the following:
>    <resource-ref>
>      <description>DB Connection</description>
>      <res-ref-name>jdbc/MYSQLDS</res-ref-name>
>      <res-type>javax.sql.DataSource</res-type>
>      <res-auth>Container</res-auth>
>  </resource-ref>

I have found that <resource-ref> is superfluous when using a
context-defined DataSource. I'm not sure if that's the way it's supposed
to be, but I have found that this doesn't matter.

> And the snippet/code I am using to acquire a datasource is as follows:
> DataSource ds = null;
> ....
> ds = (DataSource)initContext.lookup("java:/comp/env/jdbc/MYSQLDS");

Looks good to me.

> When the app is run, I get back
> java.lang.Exception: org.apache.tomcat.dbcp.dbcp.BasicDataSource
>    dbtest.HelloWorld.execute(
>    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>    sun.reflect.NativeMethodAccessorImpl.invoke(
>    sun.reflect.DelegatingMethodAccessorImpl.invoke (
>    java.lang.reflect.Method.invoke(

Can you give us the full stack trace? All I see is reflection code in
there. Is there a message? java.lang.Exception is just a little less
useful than getting a java.lang.Throwable.

- -chris
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla -


To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message