简体   繁体   English

将字节数组转换为java.sql.Clob

[英]convert byte array to java.sql.Clob

Is there any way to convert a byte array into java.sql.Clob ? 有什么办法可以将字节数组转换为java.sql.Clob吗?

I am having this type of issue... 我遇到这类问题...

getHibernateTemplate().save(object)

Where object is having a field private Clob docData; 如果对象具有private Clob docData;字段private Clob docData; and the similar is mapped into oracle table as CLOB 并且类似的内容作为CLOB映射到oracle表中

This docData clob is getting formed from somewhere in my java code like Hibernate.createClob(someString) 这个docData clob是从我的Java代码中的某个地方形成的,例如Hibernate.createClob(someString)

I tried to save it with type="clob" but getting cann't cast com.sun.proxy$Proxy124 to oracle.sql.CLOB . 我试图用type="clob"保存它,但是cann't cast com.sun.proxy$Proxy124 to oracle.sql.CLOB I have tried many ways to remove this Proxy but finally failed. 我尝试了多种方法来删除此代理,但最终失败了。

So I have decided to go like byte[] data = IOUtils.toByteArray(docData.getCharacterStream()); 所以我决定去像byte[] data = IOUtils.toByteArray(docData.getCharacterStream()); / byte[] data = IOUtils.toByteArray(docData.getAsciiStream()) and saving it as type="binary" but I am getting Caused by: java.sql.BatchUpdateException: ORA-01461: can bind a LONG value only for insert into a LONG column . / byte[] data = IOUtils.toByteArray(docData.getAsciiStream())并将其保存为type="binary"但我得到的Caused by: java.sql.BatchUpdateException: ORA-01461: can bind a LONG value only for insert into a LONG column

So now I want to create as a Clob from byte[]. 所以现在我想从byte []创建为Clob。

Any help welcome. 任何帮助欢迎。

Note earlier I was using Hibernate 3.3 and it was working fine without any such byte array conversion and etc...now I have upgraded to Hibernate 3.6.10 and getting this issue. 请注意,之前我使用的是Hibernate 3.3,并且没有任何此类字节数组转换等就可以正常工作。现在我已升级到Hibernate 3.6.10,并收到了此问题。

I'm using this method to create Blobs: 我正在使用此方法创建Blob:

org.hibernate.engine.jdbc.NonContextualLobCreator.NonContextualLobCreator.INSTANCE.createBlob( buffer )

where buffer is an array of bytes. 其中buffer是字节数组。

There are 2 similar methods for creating CLOBs: 有两种创建CLOB的类似方法:

NonContextualLobCreator.INSTANCE.createClob( reader, length )
NonContextualLobCreator.INSTANCE.createClob( string )

Pick the one that fits better with your data. 选择一个更适合您的数据的数据。

Your error message says 您的错误消息说

cann't cast com.sun.proxy$Proxy124 to oracle.sql.CLOB 无法将com.sun.proxy $ Proxy124转换为oracle.sql.CLOB

In the rest of your text you are referring to java.sql.Clob Check your imports, you might be using the clob from the oracle.sql package instead of the java.sql package somewhere. 在本文的其余部分中,您指的是java.sql.Clob检查您的导入,您可能使用的是oracle.sql包中的clob,而不是某个地方的java.sql包。

Well, issue is resolved. 好了,问题解决了。 I kept the java data type as 'Clob' only and made the hibernate mapping like type="string" . 我仅将Java数据类型保留为'Clob',并进行了类似于type="string"的休眠映射。 Issue got resolved since my digital sign data does not contain more than 2 MB (that java string max supports). 由于我的数字签名数据包含的内存不超过2 MB(java字符串max支持),因此问题已解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM