JDBC Driver for SQL/MX Programmer's Reference
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.
Writing ASCII or Unicode Data to a CLOB
Column
You can write ASCII or Unicode data to a CLOB column as follows.
Note: Multibyte Character Set (MBCS) data ASCII data are handled the same way.
ASCII Data●
Unicode Data●
ASCII Data
You can write ASCII or MBCS 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.