You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by shawn <ja...@koyuru.com> on 2002/12/23 03:04:33 UTC
ClassCastException Conn=dataSource.getConnection();
I am getting a java.lang.ClassCastException
from Connection conn = datasource.getConnection();
in the folowing:
try {
Context ctx = new InitialContext();
if(ctx == null )
{throw new Exception("Boom - No Context");}
DataSource
dataSource2=(DataSource)ctx.lookup("java:comp/env/jdbc/");
if(dataSource2 == null )
{throw new Exception("Boom - No dataSource");}
conn = dataSource2.getConnection();
}
Why would that be?
TIA
Shawn
PS the ds ="null" error I had earlier was due to not setting up my root
context properly. That document base threw me off.
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
OK Re: ClassCastException Conn=dataSource.getConnection();
Posted by shawn <ja...@koyuru.com>.
I see now. Thanks.
My confusion was this in server.xml
<!-- Tomcat Root Context -->
<!--
<Context path="" docBase="ROOT" debug="0"/>
-->
so I had
<Context path="" docBase="root"
debug="5" reloadable="true" crossContext="true">...
instead of
<Context path="/root" docBase="root"
debug="5" reloadable="true" crossContext="true">...
and
DataSource
> > dataSource2=(DataSource)ctx.lookup("java:comp/env/jdbc/");
instead of
DataSource
dataSource2=(DataSource)ctx.lookup("java:comp/env/jdbc/root");
> It's because jdbc is not a datasource, it's a container (or something
> similar. I have not the time to look it up).
>
> In your server.xml/web.xml files you should have a resource that's probably
> named "jdbc/myConnection".
>
> Your code should read
>
> dataSource2=(DataSource)ctx.lookup( "java:comp/env/jdbc/myConnection" );
>
> This of course is a guess. Without your config file, it's hard to tell.
>
> Sorry if this is a duplicate post, but I replied from the wrong account
> earlier.
>
> Andy
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: ClassCastException Conn=dataSource.getConnection();
Posted by Andy Meadows <ja...@meadowsdesign.cc>.
It's because jdbc is not a datasource, it's a container (or something
similar. I have not the time to look it up).
In your server.xml/web.xml files you should have a resource that's probably
named "jdbc/myConnection".
Your code should read
dataSource2=(DataSource)ctx.lookup( "java:comp/env/jdbc/myConnection" );
This of course is a guess. Without your config file, it's hard to tell.
Sorry if this is a duplicate post, but I replied from the wrong account
earlier.
Andy
----- Original Message -----
From: "shawn" <ja...@koyuru.com>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Sunday, December 22, 2002 9:04 PM
Subject: ClassCastException Conn=dataSource.getConnection();
> I am getting a java.lang.ClassCastException
>
> from Connection conn = datasource.getConnection();
> in the folowing:
>
> try {
> Context ctx = new InitialContext();
> if(ctx == null )
> {throw new Exception("Boom - No Context");}
>
>
> DataSource
> dataSource2=(DataSource)ctx.lookup("java:comp/env/jdbc/");
> if(dataSource2 == null )
> {throw new Exception("Boom - No dataSource");}
>
> conn = dataSource2.getConnection();
> }
>
> Why would that be?
>
> TIA
>
> Shawn
>
> PS the ds ="null" error I had earlier was due to not setting up my root
> context properly. That document base threw me off.
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: ClassCastException Conn=dataSource.getConnection();
Posted by Andy Meadows <an...@meadowsdesign.cc>.
It's because jdbc is not a datasource, it's a container (or something
similar. I have not the time to look it up).
In your server.xml/web.xml files you should have a resource that's probably
named "jdbc/myConnection".
Your code should read
dataSource2=(DataSource)ctx.lookup( "java:comp/env/jdbc/myConnection" );
This of course is a guess. Without your config file, it's hard to tell.
Andy
----- Original Message -----
From: "shawn" <ja...@koyuru.com>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Sunday, December 22, 2002 9:04 PM
Subject: ClassCastException Conn=dataSource.getConnection();
> I am getting a java.lang.ClassCastException
>
> from Connection conn = datasource.getConnection();
> in the folowing:
>
> try {
> Context ctx = new InitialContext();
> if(ctx == null )
> {throw new Exception("Boom - No Context");}
>
>
> DataSource
> dataSource2=(DataSource)ctx.lookup("java:comp/env/jdbc/");
> if(dataSource2 == null )
> {throw new Exception("Boom - No dataSource");}
>
> conn = dataSource2.getConnection();
> }
>
> Why would that be?
>
> TIA
>
> Shawn
>
> PS the ds ="null" error I had earlier was due to not setting up my root
> context properly. That document base threw me off.
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>