What database are you using? For instance, if you are using Oracle, there are special API's (i.e. non-standard
JDBC) in the drivers that can be used to persist BLOB data.
For Oracle Databases:
-----------------------
First you need a reference to the BLOB. Then you write the data to the BLOB, which buffers it. Finally, you update the BLOB column with the modified BLOB, like this:
//Use oracle.sql.BLOB because java.sql.Blob lacks setBytes()
//JDBC3 java.sql.Blob adds the method setBytes(int,byte[])
//Oracle JDBC uses the method putBytes(int,byte[])
oracle.sql.BLOB dbBlob = (oracle.sql.BLOB)rs.getBlob(1);
//update blob
ps = cxn.prepareStatement(sqlSetBlob);
ps.setString(2,SomeValue);
dbBlob.putBytes(1,blob.getRaw());
/*
You can't do this:
ps.setBinaryStream(1,blob.getInputStream(),blob.getRaw().length);
You must do it like this:
ps.setBlob(1,dbBlob);
Which is weird because you CAN do this:
InputStream is = rs.getBinaryStream(1);
Note that if the column were declared LONGVARBINARY then
setBinaryStream() would work.
*/
ps.setBlob(1,dbBlob);
cxn.commit();