JDBC/MX 5.0 Driver for SQL/MX Programmer's Reference (SQL/MX 2.x)
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.
ASCII Data
Unicode Data
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.
Clob myClob = null;
// stream begins at position 1
long pos = 1;
// Example string containing the Unicode data
String s = “TEST_UNICODE_DATA”;
// 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);
Inserting CLOB Data by Using the PreparedStatement Interface
You can use the PreparedStatement interface to insert a CLOB column with data as follows:
ASCII Data
Unicode Data
ASCII Data
You can insert a CLOB column with ASCII or Unicode data from a FileInputSteam. You must use the
PreparedStatement interface to insert the CLOB column.
FileInputStream inputAsciiStream = new FileInputStream(myClobTestFile);
int clobLen = inputAsciiStream.available();
PreparedStatement ps = conn.prepareStatement("insert










