tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <sean.schofi...@verizon.net>
Subject DataSource Problems - Unresolved Issues
Date Sun, 04 Aug 2002 15:11:47 GMT
I've been having extreme difficulty getting the DataSource to work with
Tomcat 4.0.4.  I did finally manage to get it working though.  I have two
goals for this email.  1) To tell people who are struggling how I got it to
work and 2) To ask the Tomcat experts if there are problems in the latest
version that require the "hacks" that I used or am I just doing things
wrong?

First, I started with Tomcat 4.0.3 (and Oracle 8i) and followed the very
limited available documentation on the subject.  I was able to get look up
my data source with JNDI but that was it.  I couldn't get an actual
connection.  Then I tried Tomcat 4.0.4 and got a new error message in the
Tomcat console about how TyrexDataSourceFactory couldn't find
org.hsql.jdbcDriver class.  That was odd b/c I was trying to use the Oracle
driver!  Btw, I did copy the oracle driver to the common/lib dir so it
should've found it.  Also, I noticed in the 4.0.4 release notes it said that
there were error msgs for Tyrex added so that's probably why I was getting
those all of a sudden.

I noticed that the "examples" Context had some mapping related to this so I
commented that out but that didn't help.  Then I decided I would look at the
source for the TyrexDataSourceFactory since I suspected that it was using
the default driver b/c it didn't know about mine (or couldn't find it).  I
changed the defaults to be the relevant stuff for my Oracle db and
recompiled that class only into a special jar which I made sure was in the
classpath before starting Tomcat.  This worked!  Actually I don't know for
sure that it worked b/c I did this at home and the db is at work but it
stopped complaining about the driver and just said it couldn't connect to
the db (which I expected).

To recap, I was using Tomcat 4.0.4 and had the Oracle driver in the
common/lib directory.  I also mapped the data source in the deployment
descriptor of my web app.  Here are the relevant portions of the server.xml
and web.xml files respectively:

<!-- Oracle Connection Pooling Stuff -->

<Context path="/ect" docBase="ect" debug="0" reloadable="false"
override="true">
    <Resource name="jdbc/ClassroomTest_DS" auth="Container"
type="javax.sql.DataSource"/>
    <ResourceParams name="jdbc/ClassroomTest_DS">
        <parameter><name>user</name><value>someUser</value></parameter>

<parameter><name>password</name><value>somePassword</value></parameter>
        <parameter>
            <name>driverClassName</name>
            <value>oracle.jdbc.driver.OracleDriver</value>
        </parameter>
        <parameter>
            <name>driverName</name>
            <value>jdbc:oracle:thin:@somePlace:1521:someName</value>
        </parameter>
        <parameter>
            <name>maxActive</name>
            <value>8</value>
        </parameter>
        <parameter>
            <name>maxIdle</name>
            <value>4</value>
        </parameter>
    </ResourceParams>
</Context>

...

<!-- deployment descriptor code -->
<resource-ref>
    <res-ref-name>jdbc/ClassroomTest_DS</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

....

// java client code (in JSP)

InitialContext jndiContext = null;
Context context = null;
DataSource dataSource = null;

try
{
    jndiContext = new InitialContext();
    context = (Context)jndiContext.lookup("java:comp/env");

    dataSource = (DataSource)context.lookup("jdbc/ClassroomTest_DS");
    System.out.println("datasource found.");

}
catch (Exception e)
{
    System.out.println("*** Lookup Failed: " + e);
}

Hopefully, this can help somebody out there get this working.  Also,
hopefully someone can explain to me what I'm doing wrong or whether there is
an outstanding issue in the Tomcat source that is being worked on.

TIA,

- sean


--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message