Hi,
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)
My problem is similar to the "Re: MySql Connector" thread of messages.
I can see the resource listed in the Tomcat Administration Tool under Tomcat
Server --> Service --> Host --> Context(/dbtest)
and all the information for the datasource looks fine (as from the
context.xml file below).
My context.xml file (placed in my webapp under META-INF) looks as follows:
<Context crossContext="true" path="/dbtest" reloadable="true">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost-dbtest-log."
suffix="txt"
timestamp="true"/>
<Resource
name="jdbc/MYSQLDS"
auth="Container"
type="javax.sql.DataSource"
maxActive="5"
maxIdle="3"
maxWait="10000"
username="myuser"
password="mypwd"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/testdb"/>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
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>
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");
....
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)
(by the way, I am running this within a Struts2 Framework)
Can anyone tell me what I am doing incorrectly still?
Thx,
Prem