JDBC Driver for SQL/MX Programmer's Reference
the next-available data locator.
Then, you must obtain the handle to the empty BLOB column by selecting the BLOB column for
update.
The following code illustrates how to obtain the handle to an empty BLOB column:
Blob myBlob = null;
Statement s = conn.createStatement();
ResultSet rs = s.executeQuery("Select myBlobColumn
from myTable where …For update");
if (rs.next())
myBlob = rs.getBlob(1);
You can now write data to the BLOB column. See Writing Binary Data to a BLOB Column.
Writing Binary Data to a BLOB Column
You can write data to the BLOB column by using Blob interfaces. The following code
illustrates using the setBinaryStream method of the Blob interface to write BLOB data.
Blob myBlob = null
// Stream begins at position 0
long pos = 1;
// Example string containing binary data
String s = "BINARY_DATA";
for (int i=0; i<5000; i++) s = s + "DATA";
// Obtain the output stream to write Blob data
OutputStream os = myBlob.setBinaryStream(pos);
// write Blob data using OutputStream
byte[] myBlobData = s.getBytes();
os.write(myBlobData);
The JDBC/MX driver splits the output stream into chunks and stores the chunks in the LOB
table.
Inserting a BLOB Column by Using the
PreparedStatement Interface
You can also insert a BLOB column that has binary data from a FileInputSteam. You must
use PreparedStatement interface to insert the BLOB column.
FileInputStream inputBinary = new
FileInputStream(myBlobTestFile);
int blobLen = inputBinary.available();