简体   繁体   English

将byte []存储在BLOB Oracle中

[英]Store byte[] in BLOB Oracle

I am doing the following to insert it in BLOB Oracle 11g. 我正在执行以下操作将其插入BLOB Oracle 11g。

Image is in Base64 encoding stored in a String extracted from XML. 图像采用Base64编码,存储在从XML提取的字符串中。

String str = "xyz...."
byte[] bytes = str.getBytes();
InputStream is = new ByteArrayInputStream(bytes);

PreparedStatement prepStmt = dbCon.prepareStatement("insert into Table(INDEX,RESPONSE_IMAGE) values(?,?);
prepStmt.setString(1, action.getIndex());
prepStmt.setBinaryStream(2, is, str.length());

What i think problem is the length of bytes of image because when i get the length() of the String it's around 200,000 bytes . 我认为问题是图像的字节长度,因为当我获得String的length()时,它约为200,000个字节

And when i do subString(3000) on the String it gets saved in BLOB column easily . 当我在String上执行subString(3000)时, 它很容易保存在BLOB列中

SO where is the Problem actually?? 所以问题实际上在哪里?

  1. Is the Length of Image is too Long? 图像长度是否太长?
  2. or I should go for any other datatype of Oracle? 还是我应该使用Oracle的任何其他数据类型?

I read that BLOB can save upto 4GB data then why not mine?? 我读到BLOB最多可以保存4GB数据,那为什么我的呢?

The Oracle tutorial for using Blobs with JDBC is here . 这里是有关将Blob与JDBC结合使用的Oracle教程。

The relevant part: 相关部分:

Clob myClob = this.con.createClob();
Writer clobWriter = myClob.setCharacterStream(1);

Together with: 和...一起:

Adding and retrieving BLOB SQL objects is similar to adding and retrieving CLOB SQL objects. 添加和检索BLOB SQL对象类似于添加和检索CLOB SQL对象。 Use the Blob.setBinaryStream method to retrieve an OutputStream object to write the BLOB SQL value that the Blob Java object (which called the method) represents. 使用Blob.setBinaryStream方法检索OutputStream对象,以写入Blob Java对象(称为方法)表示的BLOB SQL值。

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

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