1

When I insert blob data into Oracle database, it is partially inserted. Iam using the following code for insertion.

oracle.sql.BLOB newBlob =oracle.sql.BLOB.createTemporary(conn, false, oracle.sql.BLOB.DURATION_SESSION);
newBlob.putBytes(1, str.getBytes());
ps.setBlob(1, newBlob);

I checked whether the data got inserted or not by querying the data and converting it into jpeg image, sometimes I am getting partial image. Rest of the image is grey. Most of the time I am getting full image perfectly. What may the reason for this partial insertion?

1
  • What is str? How are you extracting it? I'm not sure if it's clear whether the problem is in the insertion, storage, retrieval or something else. Commented Oct 9, 2012 at 19:19

1 Answer 1

1

You're storing the bytes of a string in the BLOB, using the default encoding. This is wrong in at least one of the following ways:

  • if you're storing character data, use a CLOB
  • if you're storing binary data, don't put it into a string.

Since you then say that you're dealing with a JPEG, I'd say that the string conversion is where you're having a problem. Trying to store a bunch of bytes in a Java String (which deals with characters) and then converting it back to bytes is just a bad idea. Use a byte[].

Sign up to request clarification or add additional context in comments.

2 Comments

str might be an input stream, not string :)
@VincentMalgrat - except that java.io.InputStream doesn't have a getBytes() method. And the OP's symptoms sound exactly like what would happen when using a string to hold bytes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.