NonStop Server for Java (NSJ) Programmer's Guide (NSJ 2.0+)

table that will be used by the application. The JDBC driver uses the BLOB properties to decide if the object to be stored or
retrieved is a BLOB. The BLOB properties are also used to decide the location where a BLOB file should be created for a
particular BLOB column in a table.
The JDBC driver also provides some preliminary error checking on the BLOB properties. It ensures that all information
required in a BlobInfo property has been provided. It also ensures that all file names and file locations are in the correct
$volume.subvolume format.
After a connection to the database has been granted to an application, the application can then use JDBC to access and use
BLOBs as it would any other SQL/MP supported data type. Client applications can use JDBC to:
Write a BLOB to a database table.
Retrieve a BLOB from a database table.
Update a BLOB stored in a database table.
Delete a row containing a BLOB from a database table.
Writing a BLOB to the Database
A JDBC application can write a BLOB to the database using the setObject( ) method in the PreparedStatement
interface. Using the SQL/MP JDBC Driver, a BLOB can be written to a database table using any of the following methods
supported by SQLMPPreparedStatement.
public void setObject(int parameterIndex, Object x, int targetSqLType, int scale)
public void setObject(int parameterIndex, Object x, int targetSqLType)
public void setObject(int parameterIndex, Object x)
where:
parameterIndex
is the parameter to be set.
x
is any Serializable Java object.
targetSqlType
should be java.sql.Types.OTHER
scale
this value is ignored for BLOBs.
Errors encountered during the writing of a BLOB to a BLOB file generate a SQLException in the following format:
SQLMP: error message. See File System error ## for further details.
where:
error message
is the error encountered while performing this operation.
error ##
is the File System error returned while writing BLOB to a BLOB file.
Note: Writing a BLOB to a database runs as a waited operation, so writing a BLOB within a thread blocks that
thread.
Example of Writing a BLOB to 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, which stores an employee's name
EMPPIC, which stores an employee's picture.
java.lang.String insertString = new String("INSERT INTO $VOL2.MYVOL.EMPLOYEE VALUES
(?,?)");