JDBC Type 4 Driver Programmer's Reference for SQL/MX Release 3.1 (H06.23+, J06.12+)

To read binary data from the BLOB column, use the Blob interface or InputStream.
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;
myBlobData = new byte[length];
is.read(myBlobData, offset, length);
Using InputStream:
// obtain the InputStream from ResultSet
InputStream is = rs.getBinaryStream("myBlobColumn");
// read Blob data using the InputStream
byte[] myBlobData;
myBlobData = new byte[length];
is.read(myBlobData, offset, length);
Updating BLOB Data
Updating Blob Objects by Using the updateBlob Method
Replacing Blob Objects
To update BLOB data, use the methods in the Blob interface or use the updateBlob method of the ResultSet interface. The Type 4 driver makes
changes to the
BLOB data directly. Therefore, the Type 4 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
Replacing Blob Objects
Updating Blob Objects by Using the updateBlob Method
Unlike some LOB support implementations, the Type 4 driver updates the BLOB data directly in the database. So, when the Blob object is 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 Using the Blob
Interface.
Use the setBinaryStream() method to 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 under Inserting a Blob Object with the setBlob
Method and Updating Blob Objects with the UpdateBlob Method.
Deleting BLOB Data
To delete BLOB data, the JDBC application uses the SQL DELETE statement to delete the row in the base table.
When the row containing the
BLOB column is deleted by the application, the corresponding BLOB data is automatically deleted by the delete trigger
associated with the base table. For information about triggers, see
Using SQL/MX Triggers to Delete LOB Data.
See also
NULL and Empty BLOB or CLOB Value.
NULL and Empty BLOB or Empty CLOB Value
The data locator can have a NULL value if the BLOB or CLOB column is omitted in the insert statement. The Type 4 driver returns NULL when the
application retrieves the value for such a column.
When the application uses the EMPTY_BLOB() function or the EMPTY_CLOB() function to insert empty BLOB or CLOB data into the BLOB or CLOB
column, the Type 4 driver returns the Blob or Clob object with no data.
Transactions Involving Blob and Clob Access