When I search the web for inserting BLOBs into Oracle database with jdbc thin driver, most of the webpages suggest a 3-step approach:
empty_blob()
If size of inserting BLOB is greater than blob.getBufferSize(), transaction is commited as soon as first chunk is written to db as default value of autoCommit property of jdbc connection is true and further chunks writes fail as db treats them as new transactions. It is suggested as follows:
a) Set jdbc connection autoCommit property to false.
conn.setAutoCommit(false);
b) Explicitely commit the transaction after uploading the whole BLOB.
while ((bytesRead = messageInputStream.read(buffer)) != -1) {
cumBytes += bytesRead;
blobOutputStream.write(buffer, 0, bytesRead);
}
conn.commit();