3 Replies Latest reply on Dec 12, 2002 2:09 PM by Jonny Miller

    Getting the Underlying Connection

    Rob Newbie

      Hello:
      I have recently upgraded to JBoss 3.X from JBoss 2.4.6. Everything was going fine until I got to the follow section of the code. I used to get the underlying connection from the ConnectionInPool class con.getUnderlyingConnection() . I needed this to execute some Oracle specify stuff.
      Now that things have changed this method of getting the connection is no longer available to me. When using the current pooling mechanism I get the following class, back: org.jboss.resource.adapter.jdbc.local.LocalConnection
      Is there any way to get the actual Connection that the LocalConnection wraps?

      Thanks in advance

      Rob

        • 1. Re: Getting the Underlying Connection
          Yusuf Newbie

          Hi Rob,

          I have currently the same problem. Did you find any solution?

          Thank you
          Yusuf

          • 2. Re: Getting the Underlying Connection
            Jonny Miller Newbie

            LocalConnection actually exposes a getUnderlyingConnection() method that returns the specific connection. I missed this the first time I was looking through the source code, it's way at the bottom.

            It was a little tricky finding the JAR that contains the LocalConnection class (located within the jboss-local-jdbc.rar file in the default deploy directory).

            // must import org.jboss.resource.adapter.jdbc.local.LocalConnection
            Connection conn = ds.getConnection();

            // to be safe, check its type before casting
            if (conn instanceof LocalConnection) {
            Connection underlying = ((LocalConnection) conn).getUnderlyingConnection();

            // Work with the underlying connection

            }

            • 3. Re: Getting the Underlying Connection
              Jonny Miller Newbie

              For some reason, my last reply is not showing up... Anyway, to re-iterate it:

              LocalConnection exposes a getUnderlyingConnection() method just like ConnectionInPool used to. The JAR containing the org.jboss.resource.adapter.jdbc.local package is located within the jboss-local-jdbc.rar file in the default server deploy directory (you will need it to compile anything that will be casting to LocalConnection).

              // be sure to import org.jboss.resource.adapter.jdbc.local.LocalConnection

              Connection conn = ((LocalConnection) ds.getConnection()).getUnderlyingConnection();