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