3 Replies Latest reply on Jun 8, 2004 11:51 AM by dannyyates

    WrappedResultSet gotcha in 3.2.4

    duslow

      I'm posting this as an FYI for those migrating from prior 3.2.x version to the latest 3.2.4 version of JBoss.

      The ResultSet class returned from a Statement.executeQuery() (and any other JDBC call) call is now a org.jboss.resource.adapter.jdbc.WrappedResultSet class type and not the ResultSet class type that the vendor's JDBC driver would typically return.

      The gotcha is that if you need to have the actual ResultSet class from your JDBC driver in order to use vendor specific methods that are not found in the ResultSet interface, you can no longer simply cast the ResultSet to your JDBC vendor's ResultSet class if you obtain that connection via the JBoss connection pools.

      For example, in order to fully access BLOB/CLOB fields in Sybase, one must do the following:

      SybResultSet rs = (SybResultSet) stmt.executeQuery(sql.toString());
      if (rs != null && rs.next()) {
       TextPointer tp = rs.getSybTextPointer("clob_field");
       tp.sendData(bytes, 0, bytes.length, false);
      }
      ...
      
      


      The above code no longer works in 3.2.4 since the JBoss specific WrappedResultSet is now returned. If you attempt to cast the WrappedResultSet to your vendor's ResultSet, you will get a ClassCastException.

      It did work fine in 3.2.3 and I presume earlier versions because the actual vendor's ResultSet class was returned. I confirmed this in 3.2.3 by simply viewing the result of a rs.getClass().getName().

      Luckily, Adrian, the author of the WrappedResultSet, was wise enough to allow us mere mortals access to the underlying ResultSet as shown below.

      WrappedResultSet wrs = (WrappedResultSet) stmt.executeQuery(sql.toString());
      SybResultSet rs = (SybResultSet) wrs.getUnderlyingResultSet();
      if (rs != null && rs.next()) {
       TextPointer tp = rs.getSybTextPointer("clob_field");
       tp.sendData(bytes, 0, bytes.length, false);
      }
      ...
      


      While the above code does work, I am a bit concerned about relying on the implementation of the JBoss specific WrappedResultSet. Plus, the JDBC code is no longer completely portable across app servers.

      I looked at the code of the WrappedResultSet and for the most part it seems that it's function is to toggle between the 1.3 and 1.4 SDK versions where new accessor methods were added to the 1.4 version of the ResultSet interface.

        • 1. Re: WrappedResultSet gotcha in 3.2.4
          dannyyates

           

          While the above code does work, I am a bit concerned about relying on the implementation of the JBoss specific WrappedResultSet. Plus, the JDBC code is no longer completely portable across app servers.


          And you're not worried about relying on the implementation of the Sybase specific ResultSet? Your JDBC code is not completely portable across database servers.

          :-)


          • 2. Re: WrappedResultSet gotcha in 3.2.4
            duslow

            I'm not as worried about being database portable since where I work is Sybase IQ (data warehouse) centric and probably will be for quite sometime to come.

            Plus, what I'm doing with the Sybase JDBC driver IS portable to any Java application be it an app server or standalone as long as what comes back from the JDBC call is Sybase's implementation of the ResultSet class. I think that is a reasonable expectation.

            Believe me, I'd rather not have to use the Sybase result set functions to write large amounts of data to CLOB/BLOB fields, but that's the only way it works in Sybase land. Sybase only supports 4-6k CLOB/BLOB write via the standard ResultSet interface's rs.setBytes() call.

            Like I said, I'm only "a bit concerned" about having to import JBoss specific classes to make the JDBC code work as it did before. I can also do class instance checking as well to toggle the use of JBoss specific class on and off. However, I still have to import the JBoss specific class to do the check.

            • 3. Re: WrappedResultSet gotcha in 3.2.4
              dannyyates

              Other options high on my list would be to beat Sybase into implementing the spec as written and not "doing a Microsoft" and making it up as they go along.

              Another option would be to consider a different driver. Try jTDS at jtds.sourceforge.net