tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Jones <>
Subject [TC4.0.1] DataSource thru JNDI -- change Factory?
Date Sat, 06 Apr 2002 00:47:17 GMT

I've gotten everything working great to get access to a JDBC DataSource
using JNDI when I use tyrex.  However, I my database driver (DB2) comes
with an implementation of javax.naming.spi.ObjectFactory, and I would
like to use it rather than the tyrex implementation because I'll get
true connection pooling that way.

I've been trying to follow the instructions I've found on the mailing
list, but things still aren't working if I try to specify a factory... 
I don't get any errors, but I get null when I try to pull out my
DataSource (see code below).

Up until now, I had been using the bitmechanic ConnectionPool, but I was
hoping to be able to take advantage of a few new features offered by
going with the "DataSource" type method of doing things (specifically,
I'd like to be able to specify a timeout on how long I'll block until I
get a database connection).  I'm in the midst of connecting our
application to two (redundant) databases, and if one database fails, I
don't want to wait around to try to get a connection to it.

I've included the relevant snippets of code below (and some comments). 
Thanks if anybody had any suggestions for me.  We're on Tomcat 4.0.1
(for easy compatibility with Cocoon 2) and Sun's JDK 1.4.


Scott Jones

server.xml (cropped to the relevant part)
<Context path="" docBase="ROOT" debug="0">
  <Resource name="jdbc/onsite" auth="Container"  
  <!-- I'm not sure if the type should be 
       (neither one works) -->
  <ResourceParams name="jdbc/onsite">
      <!-- everything works through tyrex if I remove this -->

web.xml (cropped to the relevant part)
    Resource reference to factory for getting database connections!
    <!-- again, I'm not sure whether this should be a  or not, but I haven't
         had any luck with either... -->

testing code
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/onsite");
if (ds != null) {
  System.out.println("Got a datasource!!!");
} else {
  System.out.println("Didn't find it...");

To unsubscribe:   <>
For additional commands: <>
Troubles with the list: <>

View raw message