如何解决“非法转换”问题插入 XML 列时出现异常?
我有一个表,其中有一列 XML 类型。当我从 Windows 上的 WebSphere 中运行的 servlet 向该表中插入一条记录时,插入成功。然而,当我在 AIX 上的 WebSphere 中运行完全相同的代码时,出现以下异常:
com.ibm.db2.jcc.c.SqlException: Illegal Conversion: Can not convert from "java.lang.String" to "java.sql.Blob"
at com.ibm.db2.jcc.c.r.a(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
我正在针对 DB2 版本 9、z/OS 数据库运行 WebSphere 6.1。
由于平台差异,这感觉很像编码问题。但谁知道呢。有什么建议吗?
I have a table with a column of type XML. When I insert a record into this table from a servlet running in WebSphere on Windows, the insert succeeds. However, when I run exactly the same code in 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.c.r.a(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'm running WebSphere 6.1 against a DB2 version 9, z/OS database.
Because of the platform difference, this feels alot like an encoding problem. But who knows. Any advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
事实证明这是 JDBC 驱动程序配置的“问题”。
在同一 JVM 中运行的另一个应用程序被配置为使用 v8 JDBC 驱动程序。我的配置为使用 v9 JDBC 驱动程序。但由于类加载的工作方式,类路径上的第一个驱动程序同时加载了这两个应用程序(恰好是 v8 驱动程序,它不适用于我的应用程序。)
修复方法是将这两个应用程序切换为使用 v9驱动程序(这很好,因为据说它完全向后兼容。)
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 was configured to use the v9 JDBC driver. But because of the way classloading works, the first one on the classpath was loading for both (which just so happened to be the v8 driver, which didn't work for my application.)
The fix was to switch both applications to use the v9 driver (which was fine, because it's supposedly completely backward compatible.)
只是猜测,因为我不使用 DB2,但 BLOB 列可能要求输入是字节数组,而不是字符串。
Just a guess, since I don't work with DB2, but a BLOB column probably requires that the input be a byte array, not a String.
我将日期传递到字符串列,如下所示
对我来说,当我将其更改为时,
:我没有上面答案中提到的任何驱动程序问题
希望这可以帮助遇到类似问题的人
For me I pass date to a string column as below
when I change it to:
I don't have any driver issue as mentioned in above answer
Hope this helps someone who got similar problem