Topic
  • 2 replies
  • Latest Post - ‏2013-10-04T23:45:26Z by PeterSchwarz
PeterSchwarz
PeterSchwarz
2 Posts

Pinned topic Unwrap WSJdbcStatement in WAS Liberty

‏2013-10-04T19:17:41Z |

I get an SQL exception when I try to unwrap a WSJdbcStatement created using an XA connection in Websphere Liberty.  Here is the relevant code snippet:

                DataSource ds = (DataSource) ctx.lookup(dataSourceName);
                if (ds == null)
                    return null;
                Connection db2conn = ds.getConnection();
                if (db2conn == null)
                    return null;
               
                db2conn.setAutoCommit(false);
                db2conn.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
                Statement updateStatement = db2conn.createStatement();
                DB2Statement db2statement = updateStatement.unwrap(DB2Statement.class);

 

Here's the error:

[err] java.sql.SQLException: DSRA9122E: com.ibm.ws.rsadapter.jdbc.WSJdbcStatement@e5613efb does not wrap any objects of type com.ibm.db2.jcc.DB2Statement.
[err]     at com.ibm.ws.rsadapter.jdbc.WSJdbcWrapper.unwrap(WSJdbcWrapper.java:495)
[err]     at com.ibm.infoscout.erg.impl.db2rdf.DB2RDFUtils.connectDB(DB2RDFUtils.java:36)
[err]     at com.ibm.infoscout.erg.impl.db2rdf.DB2ERGraph.<init>(DB2ERGraph.java:104)
[err]     at com.ibm.infoscout.erg.impl.db2rdf.DB2ERGFactory.createERG(DB2ERGFactory.java:39)

 

The JDBC provider configuration looks like this:

 

  </dataSource>      
    <library id="DB2JCC4Lib">
        <fileset dir="C:/Program Files/IBM/SQLLIB_02/java" includes="db2jcc4.jar db2jcc_license_cu.jar"/>
    </library>
    <dataSource id="erg" jndiName="jdbc/erg" type="javax.sql.XADataSource">
        <jdbcDriver libraryRef="DB2JCC4Lib"/>
        <properties.db2.jcc serverName="${erg.db.host}" portNumber="${erg.db.port}" databaseName="${erg.db.name}"
                    user="${erg.db.user}" password="${erg.db.password}" enableExtendedIndicators="2"/>
    </dataSource>
 

The same error occurs if I try to unwrap the connection instead of the statement.

 

Anyone know what I am doing wrong??

 

Thanks,

Peter

 

  • njr11
    njr11
    14 Posts
    ACCEPTED ANSWER

    Re: Unwrap WSJdbcStatement in WAS Liberty

    ‏2013-10-04T20:46:44Z  

    Your usage looks correct.  One other thing to verify is that the class you are trying to unwrap comes from the same classloader as the data source.
    The configuration of the application should include,

    <application ...>
      <classloader commonLibraryRef="DB2JCC4Lib"/>
    </application>

  • njr11
    njr11
    14 Posts

    Re: Unwrap WSJdbcStatement in WAS Liberty

    ‏2013-10-04T20:46:44Z  

    Your usage looks correct.  One other thing to verify is that the class you are trying to unwrap comes from the same classloader as the data source.
    The configuration of the application should include,

    <application ...>
      <classloader commonLibraryRef="DB2JCC4Lib"/>
    </application>

  • PeterSchwarz
    PeterSchwarz
    2 Posts

    Re: Unwrap WSJdbcStatement in WAS Liberty

    ‏2013-10-04T23:45:26Z  
    • njr11
    • ‏2013-10-04T20:46:44Z

    Your usage looks correct.  One other thing to verify is that the class you are trying to unwrap comes from the same classloader as the data source.
    The configuration of the application should include,

    <application ...>
      <classloader commonLibraryRef="DB2JCC4Lib"/>
    </application>

    Thanks!  That was my problem!  Two classloaders were tripping over each other.

     

    Peter