You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Dhiren Bhatia <dh...@gmail.com> on 2005/05/09 07:36:13 UTC
DBCP ClassCastException
Hi all,
I'm getting a the following ClassCastException running Tomcat 5.5.9 with
MySQL
java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.BasicDataSource
Here's the relevant code:
*Java code:*
org.apache.commons.dbcp.BasicDataSource datasource;
datasource = (BasicDataSource)ctx.lookup("java:comp/env/jdbc/myserver");
*web.xml*
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/myserver</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
*server.xml*
*....*
<ResourceParams name="jdbc/myserver">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
*...*
This same code works in Tomcat 5.0.30.
Has anything changed? Am I missing something?
Thanks.
Re: DBCP ClassCastException
Posted by Dhiren Bhatia <dh...@gmail.com>.
Hi Lutz,
I changed the Resource tag definition to:
<Resource name="jdbc/myserver" auth="Container" type="javax.sql.DataSource
"
maxActive="100" maxIdle="30" maxWait="10000"
driverClassName="com.mysql.jdbc.Driver"/>
I'm setting the username/password and jdbcurl using code.
I still get the same ClassCastException. Is Tomcat instantiating the
correct DataSourceFactory?
I have the commons-dbcp-1.2.1.jar in my ${TOMCAT_HOME}/common/lib
Thanks,
Dhiren
On 5/8/05, Lutz Zetzsche <Lu...@sea-rescue.de> wrote:
>
> Hi Dhiren,
>
> Am Montag, 9. Mai 2005 07:36 schrieb Dhiren Bhatia:
> > Hi all,
> >
> > I'm getting a the following ClassCastException running Tomcat 5.5.9
> > with MySQL
> >
> > java.lang.ClassCastException:
> > org.apache.tomcat.dbcp.dbcp.BasicDataSource
> >
> > Here's the relevant code:
> > *Java code:*
> > org.apache.commons.dbcp.BasicDataSource datasource;
> >
> > datasource =
> > (BasicDataSource)ctx.lookup("java:comp/env/jdbc/myserver");
> >
> > *web.xml*
> > <resource-ref>
> > <description>DB Connection</description>
> > <res-ref-name>jdbc/myserver</res-ref-name>
> > <res-type>javax.sql.DataSource</res-type>
> > <res-auth>Container</res-auth>
> > </resource-ref>
> > *server.xml*
> > *....*
> > <ResourceParams name="jdbc/myserver">
> > <parameter>
> > <name>factory</name>
> > <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
> > </parameter>
> > *...*
> >
> >
> > This same code works in Tomcat 5.0.30.
> >
> > Has anything changed? Am I missing something?
>
> Yes. The syntax for the Resource tag in the server.xml has changed. The
> resource parameters are no longer defined in tags nested into the
> Resource tag, but in attributes of the tag. This is an example from the
> Tomcat 5.5 documentation:
>
> <Resource name="jdbc/TestDB" auth="Container"
> type="javax.sql.DataSource" maxActive="100" maxIdle="30"
> maxWait="10000" username="javauser" password="javadude"
> driverClassName="com.mysql.jdbc.Driver"
> url="jdbc:mysql://localhost:3306/javatest?autoReconnect=true"/>
>
>
> http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-datasource-examples-howto.html
>
> Best wishes,
>
> Lutz
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
Re: DBCP ClassCastException
Posted by Lutz Zetzsche <Lu...@sea-rescue.de>.
Hi Dhiren,
Am Montag, 9. Mai 2005 07:36 schrieb Dhiren Bhatia:
> Hi all,
>
> I'm getting a the following ClassCastException running Tomcat 5.5.9
> with MySQL
>
> java.lang.ClassCastException:
> org.apache.tomcat.dbcp.dbcp.BasicDataSource
>
> Here's the relevant code:
> *Java code:*
> org.apache.commons.dbcp.BasicDataSource datasource;
>
> datasource =
> (BasicDataSource)ctx.lookup("java:comp/env/jdbc/myserver");
>
> *web.xml*
> <resource-ref>
> <description>DB Connection</description>
> <res-ref-name>jdbc/myserver</res-ref-name>
> <res-type>javax.sql.DataSource</res-type>
> <res-auth>Container</res-auth>
> </resource-ref>
> *server.xml*
> *....*
> <ResourceParams name="jdbc/myserver">
> <parameter>
> <name>factory</name>
> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
> </parameter>
> *...*
>
>
> This same code works in Tomcat 5.0.30.
>
> Has anything changed? Am I missing something?
Yes. The syntax for the Resource tag in the server.xml has changed. The
resource parameters are no longer defined in tags nested into the
Resource tag, but in attributes of the tag. This is an example from the
Tomcat 5.5 documentation:
<Resource name="jdbc/TestDB" auth="Container"
type="javax.sql.DataSource" maxActive="100" maxIdle="30"
maxWait="10000" username="javauser" password="javadude"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/javatest?autoReconnect=true"/>
http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-datasource-examples-howto.html
Best wishes,
Lutz
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org