tomcat-users mailing list archives

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

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.

Cheers,

Scott Jones

server.xml (cropped to the relevant part)
===============================================
<Context path="" docBase="ROOT" debug="0">
  <Resource name="jdbc/onsite" auth="Container"  
    type="javax.sql.DataSource"/>
  <!-- I'm not sure if the type should be 
       COM.ibm.db2.jdbc.DB2DataSource 
       (neither one works) -->
  <ResourceParams name="jdbc/onsite">
    <parameter>
      <name>factory</name>
      <value>COM.ibm.db2.jdbc.DB2DataSourceFactory</value>
      <!-- everything works through tyrex if I remove this -->
    </parameter>
    <parameter>
      <name>user</name>
      <value>XXXXXXX</value>
    </parameter>
    <parameter>
      <name>password</name>
      <value>XXXXXXX</value>
    </parameter>
    <parameter>
      <name>driverClassName</name>
      <value>COM.ibm.db2.jdbc.app.DB2Driver</value>
    </parameter>
    <parameter>
      <name>driverName</name>
      <value>jdbc:db2:scottdev</value>
    </parameter>
  </ResourceParams>
</Context>

===============================================================
web.xml (cropped to the relevant part)
===============================================================
<resource-ref>
  <description>
    Resource reference to factory for getting database connections!
  </description>
  <res-ref-name>
    jdbc/onsite
  </res-ref-name>
  <res-type>
    javax.sql.DataSource 
    <!-- again, I'm not sure whether this should be a 
         COM.ibm.db2.jdbc.DB2DataSource or not, but I haven't
         had any luck with either... -->
  </res-type>
  <res-auth>
    Container
  </res-auth>
</resource-ref>

====================================
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:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>


Mime
View raw message