JDBC Type 2 Driver Programmer's Reference for SQL/MX Release 3.2.1 (H06.26+, J06.15+)

Storing CLOB Data
“Inserting CLOB Columns by Using the Clob Interface (page 46)
“Writing ASCII or Unicode Data to a CLOB Column (page 46)
“Inserting CLOB Data by Using the PreparedStatement Interface (page 47)
“Inserting a Clob Object by Using the setClob Method” (page 47)
Inserting CLOB Columns by Using the Clob Interface
When you insert a row containing a CLOB data type, and before the column can be updated with
real CLOB data, you can insert a row that has an "empty" CLOB value . You can insert an empty
CLOB value in a NonStop SQL/MX database by specifying EMPTY_CLOB() function for the CLOB
column in the insert statement.
The JDBC/MX driver scans the SQL string for the EMPTY_CLOB() function and substitutes the
next-available data locator.
Then, you must obtain the handle to the empty CLOB column by selecting the CLOB column for
update.
NOTE: Do not rename the CLOB column in the select query.
The following code illustrates how to obtain the handle to an empty CLOB column:
Clob myClob = null;
Statement s = conn.createStatement();
ResultSet rs = s.executeQuery("Select myClobColumn
from myTable where .for update");
if (rs.next())
myClob = rs.getClob(1);
You can now write data to the CLOB column. See “Writing ASCII or Unicode Data to a CLOB
Column (page 46).
Writing ASCII or Unicode Data to a CLOB Column
You can write ASCII or Unicode data to a CLOB column as follows.
ASCII Data (page 46)
“Unicode Data (page 46)
ASCII Data
You can write ASCII or Unicode data to the CLOB column by using the Clob interface. The following
code illustrates using the setAsciiStream method of the Clob interface to write CLOB data.
Clob myClob = null;
// stream begins at position 1
long pos = 1;
// Example string containing data
String s = "TEST_CLOB";for (int i=0; i<5000; i++) s = s + "DATA";
// Obtain the output stream to write Clob data
OutputStream os = myClob.setAsciiStream(pos);
// write Clob data using OutputStream
byte[] myClobData = s.getBytes();
os.write(myClobData);
The JDBC/MX driver splits the output stream into chunks and stores the chunks in the LOB table.
Unicode Data
The following code illustrates how to write Unicode data to a CLOB column after obtaining the
handle to the empty CLOB column.
46 Working with BLOB and CLOB Data