You can use a AS400JDBCBlob object to access binary large objects (BLOBs), such as sound byte (.wav) files or image (.gif) files.
The key difference between the AS400JDBCBlob class and the AS400JDBCBlobLocator class is where the blob is stored. With the AS400JDBCBlob class, the blob is stored in the database, which inflates the size of the database file. The AS400JDBCBlobLocator class stores a locator (think of it as a pointer) in the database file that points to where the blob is located.
With the AS400JDBCBlob class, the lob threshold property can be used. This property specifies the maximum large object (LOB) size (in kilobytes) that can be retrieved as part of a result set. LOBs that are larger than this threshold are retrieved in pieces using extra communication to the server. Larger LOB thresholds reduce the frequency of communication to the server, but they download more LOB data, even if it is not used. Smaller lob thresholds may increase frequency of communication to the server, but they only download LOB data as it is needed. See JDBC properties for information about additional properties that are available.
Using the AS400JDBCBlob class, you can do the following:
The following examples show how to use the AS400JDBCBlob class to read from a blob and update a blob:
Example: Using the AS400JDBCBlob class to read from a blob
Blob blob = resultSet.getBlob(1); long length = blob.length(); byte[] bytes = blob.getBytes(1, (int) length);
Example: Using the AS400JDBCBlob class to update a blob
ResultSet rs = statement.executeQuery ("SELECT BLOB FROM MYTABLE"); rs.absolute(5); Blob blob = rs.getBlob(1); // Change the bytes in the blob, starting at the seventh byte // of the blob blob.setBytes (7, new byte[] { (byte) 57, (byte) 58, (byte) 98}); //Update the blob in the result set, changing the blob starting // at the seventh byte of the blob (1-based) and truncating the // blob at the end of the updated bytes (the blob now has 9 bytes). rs.updateBlob(1, blob); // Update the database with the change. This will change the blob // in the database starting at the seventh byte of the blob, and // truncating at the end of the updated bytes. rs.updateRow(); rs.close();
You can use a AS400JDBCBlobLocator object to access a binary large objects.
Using the AS400JDBCBlobLocator class, you can do the following: