Unless you modifed things to use DBCP instead of Tyrex, Tomcat-4.0.3 is set up to use Tyrex. You can save yourself a lot of headache and simply upgrade to Tomcat-4.1.12. It officially uses DBCP instead of Tyrex for JNDI DataSource config and you won't be lost in the dark ages with a codebase that isn't being maintained other than security bugfixes.
Jake
At 02:18 PM 12/15/2002 +0200, you wrote:
I'm trying to use a JNDI name for a JDBC resource. Configuration is as follows:Tomcat 4.0.3 DBCP 1.0 In the server.xml, I have the following DefaultContext entry. (It must be DefaultContext because there are 3 other webapps that use the same database) <DefaultContext> <Resource auth="Container" name="jdbc/eproject" type="javax.sql.DataSource"/> <ResourceParams name="jdbc/eproject"> <parameter> <name>factory</name> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value></parameter> <parameter> <name>validationQuery</name> <value>select * from groups</value></parameter> <parameter> <name>maxWait</name> <value>10000</value></parameter> <parameter> <name>maxActive</name> <value>100</value></parameter> <parameter> <name>username</name> <value>username</value></parameter> <parameter> <name>password</name> <value>password</value></parameter> <parameter> <name>url</name> <value>jdbc:mysql://quantranet:3306/eproject?autoReconnet=true</value> </parameter> <parameter> <name>driverClassName</name> <value>org.gjt.mm.mysql.Driver</value></parameter> <parameter> <name>maxIdle</name> <value>30</value></parameter> </ResourceParams> </DefaultContext> And in the web.xml: <resource-ref id="ResourceRef_1039888737098"> <description>none</description> <res-ref-name>jdbc/eproject</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> I think there isn't a problem with JNDI. jndiContext.lookup() calls successfully return an "object". It returns the correct object, which is BasicDataSource (a class that implements javax.sql.DataSource). I re-evaluated the code, so jndi.lookup() returns an object that has the name "org.apache.commons.dbcp.BasicDataSource" which implements the javax.sql.DataSource interface. But... I don't know how, I'm getting a ClassCastException when I cast it to DataSource to get a connection! (btw, returned object is not an "instanceof" javax.sql.DataSource, but getClass().getInterfaces() has javax.sql.DataSource) initContext = new InitialContext(); envContext = (Context)initContext.lookup("java:/comp/env"); DataSource ds = (DataSource)envContext.lookup("jdbc/eproject"); or, initContext = new InitialContext(); envContext = (DataSource)initContext.lookup ("java:/comp/env/jdbc/eproject"); fails on the lines which I'm trying to cast DataSource. So, how can it be? I really appreciate the one who can tell me why! PS: commons-collections, commons-dbcp, commons-pool is in %CATALINA_HOME%\common\lib along with mysql-connector and they are in .jar format as described in JNDI-Resources HOWTO. /tb.
