2 Replies Latest reply on Apr 21, 2004 10:22 AM by ricardoarguello

    Can I access the drivers connection object

    rupshall

      Is it possible to access the drivers actual connection object ainstead of the generic sql.Connection object?

      This example might make more sense:

      I am using:

      <driver-class>com.ibm.as400.access.AS400JDBCDriver</driver-class>

      in my -ds.xml file. The connection works perfectly in all my Entity Beans. What I want to do now is create a Session Bean that uses the AS400 toolbox classes to interact with legacy programs on our iSeries/AS400. To do this I need a copy of the toolbox class:

      com.ibm.as400.access.AS400

      This connection can be obtained from the AS400JDBCConnection.getSystem() method but I get a ClassCastException when I try:

      AS400JDBCConnection as400conn = (AS400JDBCConnection) conn;
      AS400 system = as400conn.getSystem();

      The AS400JDBCDriver should create an AS400JDBCConnection but I cannot find a way to get access to Connection in this form.

      Is it possible to do something like this?

        • 1. Re: Can I access the drivers connection object

           

          Connection c = dataSource.getConnection();
          org.jboss.resource.adapter.jdbc.WrappedConnection wc = (WrappedConnection) c;
          AS400JDBCConnection ajc = (AS400JDBCConnection) wc.getUnderlyingConnection();
          


          Be careful.

          • 2. Re: Can I access the drivers connection object
            ricardoarguello

            If you don't want to import org.jboss.* classes into your project, you could do this:

            public static OracleConnection getOracleConnection(Connection conFromPool)
            throws SQLException {
            
             try {
             Class[] parms = null;
             Method method =
             (conFromPool.getClass()).getMethod("getUnderlyingConnection",
             parms);
             return (OracleConnection) method.invoke(conFromPool, parms);
            
             } catch (InvocationTargetException ite) {
             throw new SQLException(ite.getMessage());
             } catch (Exception e) {
             throw new SQLException(e.getMessage());
             }
            }
            


            Change OracleConnection with AS400JDBCConnection, or return Object and cast as needed.

            Ricardo