0 Replies Latest reply on Jun 7, 2006 3:52 AM by Marco Bosio

    ClassCastException for WrappedConnection in Jboss - strange

    Marco Bosio Newbie

      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.