Inserting Blob in Oracle DB
807598Apr 18 2006 — edited Apr 18 2006Hi 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