简体   繁体   中英

Store byte[] in BLOB Oracle

I am doing the following to insert it in BLOB Oracle 11g.

Image is in Base64 encoding stored in a String extracted from 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 .

And when i do subString(3000) on the String it gets saved in BLOB column easily .

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?

I read that BLOB can save upto 4GB data then why not mine??

The Oracle tutorial for using Blobs with JDBC is here .

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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