-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Prem,

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
problem?

> 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(HelloWorld.java:53)
>    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>    sun.reflect.NativeMethodAccessorImpl.invoke(
> NativeMethodAccessorImpl.java:39)
>    sun.reflect.DelegatingMethodAccessorImpl.invoke (
> DelegatingMethodAccessorImpl.java:25)
>    java.lang.reflect.Method.invoke(Method.java:585)

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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGpQTx9CaO5/Lv0PARAhfCAJ9B3Hkd1lra9+Dd9+4ysqu2w90ZfgCeOlq3
I/uYB+efFUY6lLrnYA38Zf0=
=6foU
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to