You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by se...@verizon.net on 2002/08/04 17:11:47 UTC

DataSource Problems - Unresolved Issues

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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: DataSource Problems - Unresolved Issues

Posted by se...@verizon.net.
Thanks for the reponse.  There seems to be some new info for me there ...

Also, I managed to get things working the right way today after figuring out
a couple of key things.  The first was that I was mapping the resource in a
<Context> in server.xml and trying to deploy the app as a WAR file at the
same time (which is apparently a no-no).

Once I moved my resource code to the <DefaultContext> the mapping worked and
I didn't need the hacked tyrex class anymore.  So apparently this problem
was confusing the tyrex class which then was resorting to the default values
for the driver, etc.  Also, it turns out I didn't need the <resource-ref>
code in my deployment descriptor either.  So I'm in business!

Thanks for the help,

- sean

----- Original Message -----
From: "anthony.dodd" <an...@ntlworld.com>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Monday, August 05, 2002 11:16 PM
Subject: Re: DataSource Problems - Unresolved Issues


> I posted some notes and source code re Tomcat 4.0.3, it might be of some
> use, see
>
> http://www.mail-archive.com/tomcat-user@jakarta.apache.org/msg56315.html
>
>
>
> ----- Original Message -----
> From: <se...@verizon.net>
> To: <to...@jakarta.apache.org>
> Sent: Sunday, August 04, 2002 8:11 AM
> Subject: DataSource Problems - Unresolved Issues
>
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: DataSource Problems - Unresolved Issues

Posted by "anthony.dodd" <an...@ntlworld.com>.
I posted some notes and source code re Tomcat 4.0.3, it might be of some
use, see

http://www.mail-archive.com/tomcat-user@jakarta.apache.org/msg56315.html



----- Original Message -----
From: <se...@verizon.net>
To: <to...@jakarta.apache.org>
Sent: Sunday, August 04, 2002 8:11 AM
Subject: DataSource Problems - Unresolved Issues


> 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:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>