Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2006

Tip: Looking for answers? Try searching our database.

ClassCastException for WrappedConnection in Jboss - strange problem

Thread view: 
puppino@gmail.com - 07 Jun 2006 08:39 GMT
I have some strange problem using jboss's WrappedConnection.

If I write this simple jsp:

<%@ page import="javax.sql.*,javax.naming.*,java.util.*,java.sql.*,
java.math.*,it.imiweb.internal.todb.*,it.imiweb.internal.todb.util.*"%>

<%
       try{
               InitialContext ctx = new InitialContext();
               DataSource ds = (DataSource)
ctx.lookup("java:/MYDATASOURCE");
               org.jboss.resource.adapter.jdbc.WrappedConnection
wc=(org.jboss.resource.adapter.jdbc.WrappedConnection)ds.getConnection();
               oracle.jdbc.driver.OracleConnection conn =
(oracle.jdbc.driver.OracleConnection)wc.getUnderlyingConnection();

// here i used the connection to call an oracle procedures using struct

               conn.close();

       }catch(Exception ex){
               ex.printStackTrace();
       }

%>

All is ok and I have any problem.

If, in my application I create an object where it get a Connection
using the same code jboss tell me this error:

java.lang.ClassCastException:
org.jboss.resource.adapter.jdbc.WrappedConnection

This is the method's code:

       protected Connection checkOutConnection() throws Exception{
               String idm =
"ContextStoredProceduresUtil.checkOutConnection - ";
               try{

                       System.out.println(idm + "Check out
connection");

                       Context ctx = new InitialContext();
                       javax.sql.DataSource ds
=(javax.sql.DataSource)ctx.lookup(this.getDataSourceName());
                       System.out.println("my class is" +
ds.getConnection().getClass());
                       WrappedConnection
wc=(WrappedConnection)ds.getConnection();
                       return wc.getUnderlyingConnection();

               }catch(Exception ex){
                       throw new Exception(idm + ex.getMessage());
               }
       }

The ClassCastException happens when I try to cast ds.getConnection(),
ma this is WrappedConnection 's object because I print before the class
name.

I don't understand why I have this problem.
I need an UnderlyingConnection to call an oracle's procedure with
object because this method with a simple ds.getConnection() and with no
procedure with object working great.

I try to use it with jboss 4.03 and 4.04

Any helps?

Luca.
Frank Langelage - 07 Jun 2006 18:59 GMT
> java.lang.ClassCastException:
> org.jboss.resource.adapter.jdbc.WrappedConnection
>
>                         WrappedConnection
> wc=(WrappedConnection)ds.getConnection();

What's the name of the class you get?
print out ds.getConnection().getClass().getName().
Andy Flowers - 07 Jun 2006 19:14 GMT
> I have some strange problem using jboss's WrappedConnection.
>
> If I write this simple jsp:
>
> <%@ page import="javax.sql.*,javax.naming.*,java.util.*,java.sql.*,
> java.math.*,it.imiweb.internal.todb.*,it.imiweb.internal.todb.util.*"%>

<snip>

>                         System.out.println("my class is" +
> ds.getConnection().getClass());
[quoted text clipped - 6 lines]
>                 }
>         }

What is output by the System.out.println(...) ?, what is the actual type of the
class ?

You might also want to use ds.getConnection().getClass().getName().


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.