ClassCastException for WrappedConnection in Jboss - strange problem

P

puppino

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.
 
F

Frank Langelage

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().
 
A

Andy Flowers

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.*"%>

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());
}
}

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().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top