JDBC Type 4 Driver 2.0 Programmer's Reference (SQL/MX 2.x)
os.write(myBlobData);
The Type 4 driver splits the output stream into chunks and stores the chunks in the LOB table.
Inserting a BLOB Column by Using the PreparedStatement Interface
To insert a BLOB column that has binary data from an InputStream, use the PreparedStatement
interface:
InputStream inputBinary;
PreparedStatement ps = conn.prepareStatement("insert
into myTable (myBlobColumn) values (?)");
ps.setBinaryStream(1, inputBinary, length_of_data);
ps.executeUpdate();
The Type 4 driver reads the data from InputStream and writes the data to the LOB table. The Type 4
driver substitutes the next-available data locator for the parameter of the BLOB column in the table.
Inserting a Blob Object by Using the setBlob Method
Your JDBC application cannot directly instantiate a Blob object. To perform an equivalent operation:
Obtain a Blob object by using the getBlob method of the ResultSet interface.1.
Insert the Blob object into another row by using the setBlob method of the
PreparedStatement interface.
2.
In this situation, the Type 4 driver generates a new data locator and copies the contents of the source
Blob into the new Blob object when the application issues the setBlob method of the
PreparedStatement interface.
Reading Binary Data from a BLOB Column
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");










