JDBC Type 4 Driver Programmer's Reference for SQL/MX Release 3.2.1

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 CLOB column in
the table.
Inserting a Clob Object by Using the setClob Method
Your JDBC application cannot directly instantiate a Clob object. To perform an equivalent operation:
1. Obtain a Clob object by using the getClob method of the ResultSet interface.
2. Insert the Clob object into another row by using the setClob method of the
PreparedStatement interface.
In this situation, the Type 4 driver generates a new data locator and, when the
PreparedStatement is executed, copies the contents of the source Clob into the new Clob
object.
Inserting a CLOB column with Unicode data using a Reader
You can use the PreparedStatement interface to insert a CLOB column with Unicode data using
a Reader.
Reader inputReader;
PreparedStatement ps = conn.prepareStatement("insert into
myTable (myClobColumn) values (?)");
ps.setCharacterStream(1, inputReader, length_of_data);
ps.executeUpdate();
Type 4 driver reads the data from a Reader and internally SQLMXClobWriter writes the data to
the LOB table. Type 4 driver substitutes the next available data locator to the parameter of the
CLOB column in the base table.
Writing Unicode data to a CLOB column
The following code illustrates how to write a Unicode data to a CLOB, after obtaining the handle
to the empty CLOB column:
long pos = 0;
// String containing the Unicode data
String s ;
// Obtain the output stream to write Clob data
Writer cw = myClob.setCharacterStream(pos);
// write Clob data using Writer
char[] myClobData = s.toCharArray();
cw.write(myClobData);
Reading CLOB Data
“Reading ASCII Data from a CLOB Column (page 58)
“Reading Unicode data from a CLOB Column (page 59)
Reading ASCII Data from a CLOB Column
To read ASCII or MBCS data from a CLOB column, use the Clob interface or InputStream.
Using the Clob interface:
// Obtain the Clob from ResultSet
Clob myClob = rs.getClob("myClobColumn");
// Obtain the input stream to read Clob data
InputStream is = myClob.getAsciiStream();
// read Clob data using the InputStream
byte[] myClobData;
myClobData = new byte[length];
is.read(myClobData, offset, length);
58 Working with BLOB and CLOB Data