Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Inserting Blob in Oracle DB

807598Apr 18 2006 — edited Apr 18 2006
Hi All,

I am a newbie in Java -- so appreciate any help/pointers that I can get.

I've a situation where in a customer is passing UTF-8 character string in the UI that needs to be stored into the BLOB column in the database. The string contains charcters like ��� etc.

I am using the following code to insert the data into the blob:

byte[] databytes = data.getBytes("UTF-8");
getblobStmt = conn.prepareStatement(getblobSql);
getblobStmt.setInt(1, file_id);
getblobRset = (OracleResultSet)getblobStmt.executeQuery();

if (getblobRset.next())
{
blob = getblobRset.getBLOB(1);
}

amountWritten = blob.putBytes(1, databytes);
long blobLength = blob.length();

System.out.println("amount written: " + amountWritten);
System.out.println("length: " + blobLength);
conn.commit();

The problem that I am facing is that the entire string is not stored -- the last few characters of the string are getting truncated.

I am not sure what is it that I am doing wrong. I am on 9i DB and if I insert the data using SQL*Plus, it goes in ok. It's only from the JSP/Java UI that I am facing this issue.

Appreciate any help.

Thanks,
Jatinder
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 16 2006
Added on Apr 18 2006
1 comment
359 views