IBM Support

WebSphere Application Server and the JDBC 4.0 Wrapper Pattern

Troubleshooting


Problem

New in JDBC 4.0: The wrapper pattern now allows JDBC programmers to access vendor-specific JDBC APIs safely in an application server managed environment. Previous to JDBC 4.0, the WebSphere Application Server proprietary WSCallHelper interface had to be used to accomplish the same task.

Symptom

If the wrapper pattern is not followed and a vendor-specific JDBC API is invoked directly, the following type of error will be logged:

[12/12/11 12:34:39:911 EDT] 00000059 SystemErr R Caused by: java.sql.SQLFeatureNotSupportedException: DSRA1300E: Feature is not implemented: PreparedStatement.setClob
[12/12/11 12:34:39:912 EDT] 00000059 SystemErr R at com.ibm.ws.rsadapter.AdapterUtil.notSupportedX(AdapterUtil.java:1306)
[12/12/11 12:34:39:912 EDT] 00000059 SystemErr R at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.setClob(WSJdbcPreparedStatement.java:1875)
[12/12/11 12:34:39:912 EDT] 00000059 SystemErr R at com.citigroup.solar.pnlview.dao.impl.ExportPnLViewDAO.putInUploadQueue(ExportPnLViewDAO.java:782)
[12/12/11 12:34:39:912 EDT] 00000059 SystemErr R ... 59 more
[12/12/11 12:34:39:913 EDT] 00000059 SystemErr R Caused by: java.lang.AbstractMethodError: java/sql/PreparedStatement.setClob(ILjava/io/Reader;)V
[12/12/11 12:34:39:913 EDT] 00000059 SystemErr R at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.setClob(WSJdbcPreparedStatement.java:1859)
[12/12/11 12:34:39:913 EDT] 00000059 SystemErr R ... 60 more

Cause

In the above example, the .setClob() method is an Oracle-specific method which is not part of standard JDBC 4.0.

Environment

Requirements to use the JDBC 4.0 wrapper pattern:

  1. WebSphere Application Server v7.0 or higher. Refer to this Information Center page for more information:
    Specifications and API documentation
    http://www14.software.ibm.com/webapp/wsbroker/redirect?version=matt&product=was-nd-dist&topic=rovr_specs
  2. JDBC 4.0-compliant JDBC driver.
    Consult with your driver vendor to determine the JDBC spec level.

Resolving The Problem

The following code snippets show how the JDBC 4.0 wrapper pattern can be used to obtain a native Oracle connection or a native Oracle PreparedStatement object:

1. Obtain an oracle.jdbc.OracleConnection:
Context ic = new InitialContext();
DataSource ds = (DataSource)ic.lookup("jdbc/OracleDS");
Connection conn = ds.getConnection();

// Returns true if this either implements the interface argument
// or is directly or indirectly a wrapper for an object that does.
if (conn.isWrapperFor(oracle.jdbc.OracleConnection.class)) {
// Returns an object that implements the given interface to
// allow access to non-standard methods, or standard methods
// not exposed by the proxy.
oracle.jdbc.OracleConnection oraCon = conn.unwrap(oracle.jdbc.OracleConnection.class);
// Do some Oracle-specific work here.
}
conn.close();


2. Obtain an OraclePreparedStatement:
Context ic = new InitialContext();
DataSource ds = (DataSource)ic.lookup("jdbc/OracleDS");
Connection conn = ds.getConnection();

PreparedStatement pstmt = conn.prepareStatement("SELECT 1 FROM DUAL");
if(pstmt.isWrapperFor(oracle.jdbc.OraclePreparedStatement.class)){
oracle.jdbc.OraclePreparedStatement opstmt = pstmt.unwrap(oracle.jdbc.OraclePreparedStatement.class);
// Do some Oracle-specific work here.
}
pstmt.close();
conn.close();




[{"Product":{"code":"SSEQTP","label":"WebSphere Application Server"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"DB Connections\/Connection Pooling","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF012","label":"IBM i"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"},{"code":"PF035","label":"z\/OS"}],"Version":"9.0;8.5;8.0;7.0","Edition":"Base;Network Deployment","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

Modified date:
15 June 2018

UID

swg21577331