OracleLobCreator needs to work on [oracle.jdbc.OracleConnection], but on …

Situation

Try to insert CLOB data to Oracle 11, but an error occurs.

spring-jdbc-3.1.0.jar

jdbcTemplate.update(INSERT_SQL, 
 new Object[] {new SqlLobValue(o.getLongString(), new OracleLobHandler()), ...},
 new int[] {Type.CLOB, ...});

Error occurs:

OracleLobCreator needs to work on [oracle.jdbc.OracleConnection], not on [weblogic.jdbc.rmi.SerialConnection_weblogic_jdbc_rmi_internal_ConnectionImpl_weblogic_jdbc_wrapper_PoolConnection_oracle_jdbc_driver_T4CConnection_1036_WLStub]: specify a corresponding NativeJdbcExtractor; nested exception is java.lang.ClassCastException: weblogic.jdbc.rmi.SerialConnection_weblogic_jdbc_rmi_internal_ConnectionImpl_weblogic_jdbc_wrapper_PoolConnection_oracle_jdbc_driver_T4CConnection_1036_WLStub cannot be cast to oracle.jdbc.OracleConnection
org.springframework.dao.InvalidDataAccessApiUsageException: OracleLobCreator needs to work on [oracle.jdbc.OracleConnection], not on [weblogic.jdbc.rmi.SerialConnection_weblogic_jdbc_rmi_internal_ConnectionImpl_weblogic_jdbc_wrapper_PoolConnection_oracle_jdbc_driver_T4CConnection_1036_WLStub]: specify a corresponding NativeJdbcExtractor; nested exception is java.lang.ClassCastException: weblogic.jdbc.rmi.SerialConnection_weblogic_jdbc_rmi_internal_ConnectionImpl_weblogic_jdbc_wrapper_PoolConnection_oracle_jdbc_driver_T4CConnection_1036_WLStub cannot be cast to oracle.jdbc.OracleConnection
 at org.springframework.jdbc.support.lob.OracleLobHandler$OracleLobCreator.createLob(OracleLobHandler.java:505) ~[spring-jdbc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
 at org.springframework.jdbc.support.lob.OracleLobHandler$OracleLobCreator.setClobAsString(OracleLobHandler.java:413) ~[spring-jdbc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
 at org.springframework.jdbc.core.support.SqlLobValue.setTypeValue(SqlLobValue.java:190) ~[spring-jdbc-3.1.0.RELEASE.jar:3.1.0.RELEASE]

 

Solution

No need to use OracleLobHandler, use DefaultLobHandler instead.

DefaultLobHandler lobhandler = new DefaultLobHandler();

jdbcTemplate.execute(
 INSERT_SQL,
 new AbstractLobCreatingPreparedStatementCallback(lobhandler) { 
   protected void setValues(PreparedStatement ps, LobCreator lobCreator) 
   throws SQLException {
     lobCreator.setClobAsString(ps, 1, o.getLongString()); 
     ... 
   }
 }
);

or

jdbcTemplate.update(INSERT_SQL, 
 new Object[] {new SqlLobValue(o.getLongString(), new DefaultLobHandler()), ...},
 new int[] {Type.CLOB, ...});

Reference

http://library.tebyan.net/ar/Viewer/Read/164709/51

http://docs.spring.io/spring/docs/3.0.0.M4/spring-framework-reference/html/ch12s07.html?ref=driverlayer.com/web

http://docs.spring.io/spring/docs/current/spring-framework-reference/html/jdbc.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s