How do I resolve an Illegal Conversion exception when pasting into an XML column?

I have a table with an XML type column. When I insert a record into this table from a servlet running in WebSphere on Windows, the insert is successful. However, when I run the exact same code on WebSphere on AIX, I get the following exception:

com.ibm.db2.jcc.c.SqlException: Illegal Conversion: Can not convert from "java.lang.String" to "java.sql.Blob" at com.ibm.db2.jcc.cra(r.java:695) at com.ibm.db2.jcc.c.uf.b(uf.java:927) at com.ibm.db2.jcc.c.uf.setString(uf.java:910) at com.ibm.ws.rsadapter.spi.InternalGenericDataStoreHelper.psSetString(InternalGenericDataStoreHelper.java:554) at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.setString(WSJdbcPreparedStatement.java:1662) at org.hibernate.type.StringType.set(StringType.java:49) at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:154) at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:131) at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2015) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2261) ... 33 more 

I am running WebSphere 6.1 for a DB2 database version 9, z / OS.

Due to the difference in platform, this feels like a coding problem. But who knows. Any tips?

+4
source share
3 answers

This turned out to be a “problem” with the JDBC driver configuration.

Another application running in the same JVM was configured to use the V8 JDBC driver. Mine has been configured to use the v9 JDBC driver. But because of how the class load works, the first one in the class path was loaded for both (which turned out to be exactly the v8 driver, which did not work for my application.)

The fix was to switch both applications to using the v9 driver (this was normal because it was supposedly completely reversed.)

+1
source

Just suppose since I am not working with DB2, but the BLOB column probably requires the input to be a byte array, not a string.

0
source

For me, I pass the date to the column of the row below

 setDate( 5, new java.sql.Date( this.prevDate.getTime() ) ); 

when i change it to:

 setString( 5, "20150404" ); 

I have no problem with the driver as indicated in the answer above

Hope this helps someone who has a similar issue.

0
source

All Articles