You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Phil Steitz <ph...@steitz.com> on 2002/07/13 05:32:04 UTC
ClassCastException when retrieving PostGres JDBC Connection from
Tomcat 4.0.4 pool
I am running Tomcat 4.0.4 using the JNDI DataSource support to access a
PostGres database.
The following throws java.lang.ClassCastException:
tyrex.jdbc.xa.EnabledDataSource
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource)
envCtx.lookup("jdbc/"+ jndiName);
return ds.getConnection();
When I build with tyrex-0.9.7.0.jar and change DataSource to
EnabledDataSource, things work fine.
Why do I get the exception and why does the fix work? Shouldn't the
type of the resource returned match the type specification in server.xml
and web.xml below?
In server.xml:
<!-- Library Database connection pool -->
<Resource name="jdbc/libraryDB"
auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/libraryDB">
<parameter>
<name>user</name>
<value>libuser</value>
</parameter>
<parameter>
<name>password</name>
<value>should_not_be_clear_text</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>org.postgresql.Driver</value>
</parameter>
<parameter>
<name>driverName</name>
<value>jdbc:postgresql://hanley/library</value>
</parameter>
</ResourceParams>
In web.xml:
<!-- Library DataSource Configuration -->
<resource-ref>
<description>
Resource reference to a factory for java.sql.Connection
instances used for connecting via JNDI to library
database as configured in the server.xml file.
</description>
<res-ref-name>jdbc/libraryDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
PostGres driver is in ${catalina.home}/common/lib
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>