tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian Munroe" <>
Subject Re: Please help...
Date Sun, 02 Sep 2007 05:17:15 GMT
On 8/31/07, Mike Cronin <> wrote:

> I am having a problem setting up a connection-pool via JNDI on Tomcat 6.0.14
> utilizing Oracle 10g. Currently I have a <Resource> for my DataSource
> referenced within a <Context> element within the server.xml file. The
> classes12.jar file which contains the Oracle Driver, exists within the
> $CATLINA-HOME/lib. I am able to successfully access my tables outside of the
> connection pool so I know that I am getting to the driver.


First thing I can tell you, quoting directly from the Tomcat Docs:

"For Tomcat 6, unlike Tomcat 4.x, it is NOT recommended to place
<Context> elements directly in the server.xml file. This is because it
makes modifing the Context configuration more invasive since the main
conf/server.xml file cannot be reloaded without restarting Tomcat."

Now that I've said that, I'll admit I struggled with connection
pooling about a month ago.  My problem was that I was trying to place
the driver jar file in either shared/lib or WEB-INF/lib.  This was
incorrect and it needed to be in $CATALINA_HOME/common/lib, where
Tomcat could manage it.  If you read the classloader section on it will make sense why this is.

You mention that it is located it $CATALINA_HOME/lib [sic] - which
I'll assume is a typo, but it leads to ambiguity - did you mean
common/lib or shared/lib?  Definitely move it to common/lib.

After trying to get my JDBC resources to work in
<GlobalNamingResource> without much luck.  I ended up placing my
<Resource> definitions in META-INF/context.xml.  I don't know if you
are trying to define a global pool for all your applications or can
live with a local app configuration, I made due with a local

Regardless, here is my "hello, world" recipe:

In META-INF/context.xml file:

<Resource name="jdbc/XEDB"

I didn't mess around with setting username and password attributes, I
just provided them within the connection URL.

Finally, in a JSP, I have the following code:

(mind you this is just a 'hello, world' - I'd never actually recommend
this in real life)

< import="javax.naming.*" />
< import="java.sql.*" />
< import="javax.sql.*" />


InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/XEDB");
Connection conn = ds.getConnection();

Statement s = conn.createStatement();

ResultSet rs = s.executeQuery("select * from hello");

while( {
    out.println(rs.getString(1) + "<br/>");



I deleted, for example, <resource-ref>'s, and basically returned
conf/server.xml and WEB-INF/web.xml back to stock, which I had mucked
up from trying things googling had suggested I try.

Hopefully this works for you too!

BTW, classes12.jar is designed for JDK 1.2 and 1.3.  From what you
mentioned, it is working just fine with your non-pooling code, but you
can download [1] a newer version (odbc14.jar comes with Oracle XE).

-- brian

[1] -

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

View raw message