NonStop Server for Java (NSJ) Programmer's Guide (NSJ 2.1+)
Errors encountered during the writing of a BLOB to a BLOB file generate an 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 the 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
stores an employee's name
EMPPIC
stores an employee's picture.
java.lang.String insertString = new String("INSERT INTO $VOL2.MYVOL.EMPLOYEE VALUES
(?,?)");
// create a PreparedStatement object for the connection
PreparedStatement psmt = con.PreparedStatement(insertString);
// set values to be inserted including a BLOB and insert a new row in the table.
psmt.setString(1, "Mickey Mouse");
psmt.setObject(2, MickyMousePic); //MickyMousePic is a serializable Java object.
psmt.executeUpdate( );
Reading a BLOB From the Database
A JDBC application can retrieve a BLOB object from the database using the getObject( ) method in the ResultSet
interface. A BLOB can also be retrieved as a byte array using the ResultSet interface. Using the SQLMP JDBC Driver, a
BLOB can be read from a database table using the following methods supported by SQLMPResultSet.
public Object getObject(int columnIndex)
public Object getObject(String columnName)
public byte[ ] getBytes(int columnIndex)
public byte[ ] getBytes(String columnName)
where:
columnName
is the name of the BLOB column.
columnIndex
is the index of the BLOB column.
Errors encountered during the retrieval of a BLOB from its BLOB file generate an SQLException with the following
message:
SQLMP: error message. See File System error ## for further details.
where:
error message
is the error encountered while performing this operation.