JDBC Driver for SQL/MP 3.0
Example of Retrieving a BLOB From the Database
This example assumes that a java.util.Properties object with BLOB properties has been created as described in
the previous example and a connection granted using this Properties object. The sample table $VOL2.MYVOL.EMPLOYEE
contains two columns:
EMPNAME
stores an employee's name.
EMPPIC
stores an employee's picture.
java.lang.String selectString = new String("SELECT * FROM $VOL2.MYVOL.EMPLOYEE");
// create a Statement object for the connection
stmt = conn.createStatement( );
// get a ResultSet with the contents of the table.
ResultSet results = stmt.executeQuery(selectString);
//retrieve content of first row
String name = results.getString(1);
Object blob = results.getObject(2);
Note: The BLOB can also be retrieved as an array of bytes instead of retrieving as an object:
byte[ ] blob_contents = results.getBytes(2);
Removing Obsolete BLOB Files
A Cleanup utility is provided to periodically remove the obsolete BLOB files from the file system. BLOB files become
obsolete because of one of these operations:
An application updates a BLOB column. The driver creates a new BLOB file to store the new BLOB object. The
driver then writes the name of the new BLOB file in the table. The BLOB file containing the original BLOB
now becomes obsolete.
The application deletes a row containing a BLOB from the table. The BLOB file name is removed from the
table and is not referenced by any other tables. The BLOB file is now obsolete.
The Cleanup utility uses a BLOB map file. The JDBC driver adds an entry for every BLOB file created by an
application to this BLOB map file. During cleanup, the JDBC driver deletes all obsolete BLOB files from the file
system and their corresponding entries from the BLOB map file.
The Cleanup utility can be run only by the owner of the BLOB map file. The owner of the application must run the
Cleanup utility to remove any obsolete BLOB files that have been created for the application from the file system. To
maintain the integrity of the application's database tables, run this utility only when none of the affected tables
containing BLOBs are in use. The Cleanup utility is a Java application, run it from the command line in this way:
java com.tandem.sqlmp.SQLMPBlobCleanup [errfile]
where:
com.tandem.sqlmp.SQLMPBlobCleanup
is the Cleanup utility
Blob map file
is the name of the BLOB map file specified by the application
errfile
errors encountered during cleanup are logged to this file