tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject tomcat 4 datasource casting
Date Mon, 20 Aug 2001 22:10:04 GMT
Hello all,

I read the great message Craig McClanahan posted in the archives  (from 
Aug 4) about how to setup and use a tomcat 4 datasource.  All has seemed 
to go pretty well, but I'm having a funny problem, which I'm not sure is a 
Tyrex problem, a Tomcat 4 problem or a Java education problem on my part 
:).  (I'm using Tomcat 4 beta 7)

When I try to get a DataSource from JNDI, I can retrieve a reference just 
fine.  The problem is that I am having trouble casting it to a 
javax.sql.DataSource.  It returns an instance of 
tyrex.jdbc.xa.EnabledDataSource.  If I try to cast to 
javax.sql.DataSource, I get a ClassCastException from the server.  I 
looked up this class in the Tyrex API docs, and it does in fact implement 
javax.sql.DataSource -- I think I should be able to cast to it because of 
that.  If I work with the tyrex implementation directly, all is ok (i.e., 
calling tyrex.jdbc.xa.EnabledDataSource.getConnection()), but I obviously 
won't want to care about the particular implementation in this case.

If it helps, here is the code I'm trying to use:

ctx = new InitialContext();
ds = (DataSource)ctx.lookup("java:comp/env/jdbc/lis_ds");

That failed, so I added this for debugging:

Object o = ctx.lookup("java:comp/env/jdbc/lis_ds");
if (o == null) {
   System.out.println("looked up a null object");
} else {
   System.out.println("o is of type: " + o.getClass().getName()); //<-- 
prints "tyrex.jdbc.xa.EnabledDataSource"

The exceptions I get are like this:

java.lang.ClassCastException: tyrex.jdbc.xa.EnabledDataSource
        at report.ReportPrefs.setDateDefaults(
        at report.ReportPrefs.<init>(
        at java.lang.Class.newInstance0(Native Method)
        at java.lang.Class.newInstance(
        at java.beans.Beans.instantiate(
        at java.beans.Beans.instantiate(

Any ideas?

Jason Vasquez

View raw message