JDBC Type 2 Driver Programmer's Reference for SQL/MX Release 3.2.1 (H06.26+, J06.15+)

Reading Binary Data from a BLOB Column
You can read binary data from the BLOB column by using the Blob interface or InputStream.
The following code illustrates how to read the binary data from the BLOB column by using the
Blob interface:
// Obtain the Blob from ResultSet
Blob myBlob = rs.getBlob("myBlobColumn");
// Obtain the input stream to read Blob data
InputStream is = myBlob.getBinaryStream();
// read Blob data using the InputStream
byte[] myBlobData = new byte[length];
is.read(myBlobData, offset, length);
To read binary data from the BLOB column by using InputStream
// obtain the InputStream from ResultSet
InputStream is = rs.getBinaryStream("myBlobColumn");
// read Blob data using the InputStream
byte[] myBlobData = new byte[length];
is.read(myBlobData, offset, length);
Updating BLOB Data
You can update BLOB data by using the methods in the Blob interface or by using the updateClob
method of the ResultSet interface. The JDBC/MX driver makes changes to the BLOB data directly.
Hence, the JDBC/MX driver returns false to the locatorsUpdateCopy method of the
DatabaseMetaData interface. Applications do not need to issue a separate update statement
to update the BLOB data.
Update BLOB data in the following ways.
“Updating Blob Objects by Using the updateBlob Method” (page 51)
“Replacing Blob Objects (page 51)
Updating Blob Objects by Using the updateBlob Method
Unlike some LOB support implementations, the JDBC/MX driver updates the BLOB data directly
in the database. So, when the Blob object is the same in the updateBlob method as the object
obtained using getBlob, the updateRow method of the ResultSet interface does nothing with
the Blob object.
When the Blob objects differ, the Blob object in the updateBlob method behaves as if the
setBlob method was issued. See Inserting a Blob Object with the setBlob Method.
Replacing Blob Objects
You can replace Blob objects in the following ways:
Use the EMPTY_BLOB() function to replace the Blob object with the empty Blob object.
Replace an existing Blob object in a row by inserting the Blob with new data as described
under “Inserting a BLOB Column by Using the Blob Interface (page 49).
Use the setBinaryStream() method of the PreparedStatement interface to replace
the existing Blob object with new BLOB data.
Use the setBlob or updateBlob methods to replace the existing BLOB objects as explained
earlier under “Inserting a Blob Object by Using the setBlob Method” (page 50) and “Updating
Blob Objects by Using the updateBlob Method” (page 51).
Deleting BLOB Data
To delete BLOB data, the JDBC application uses the SQL DELETE statement to delete the row in the
base table.
Reading Binary Data from a BLOB Column 51