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?

4

1 回答 1

1

您使用默认编码将字符串的字节存储在 BLOB 中。这至少在以下一种方式中是错误的:

  • 如果要存储字符数据,请使用 CLOB
  • 如果要存储二进制数据,请不要将其放入字符串中。

既然您说您正在处理 JPEG,我会说字符串转换是您遇到问题的地方。尝试将一堆字节存储在 Java 字符串(处理字符)中,然后将其转换回字节只是一个坏主意。使用byte[].

于 2012-10-09T19:21:37.350 回答