I am migrating from Oracle to DB2 v 7.2.
The problem is that I didn't find a way to write CLOBs through Java.
I am using the db2java.zip which is on the same CD with the DB2 v 7.2.
My input is a java.io.Reader, so the question is what should I do in order to write to a CLOB field. The OS is Windows NT.
My current work around is to create a file, on the disk, from the java.io.Reader, open an FileInputStream on the temporary file and use the PreparedStatement.setAsciiStream method. Of course this is not acceptable from the performances point of view.
During my searches on ibm.com I found the class com.ibm.as400.access.AS400JDBCBlob,
having methods as setBinaryStream which 'returns a stream that an application can use to write to this BLOB'. It looks that it can serve my purposes, as I can read from my java.io.Reader and write using the returned java.iutputStream.
But, I didn't find anything similar for Windows NT.
Following is the code we are currently use with Oracle.
...............
stmt = con.prepareStatement("INSERT INTO CWMDSegment (Name,SegmentType) values (?,empty_clob()"
stmt.setString(1, name);
stmt.execute ();
stmt.close();
stmt = con.prepareStatement("SELECT Segment FROM CWMDSegment WHERE name=? for update"
stmt.setString(1, name);
rset = stmt.executeQuery();
rset.next();
CLOB blob = ((OracleResultSet)rset).getCLOB(1);
outstream = blob.getCharacterOutputStream();
int size = blob.getBufferSize();
char[] buffer = new char[size];
int length = -1;
while ((length = rd.read(buffer,0,size)) > 0)
outstream.write(buffer, 0, length);
...............
The problem is that I didn't find a way to write CLOBs through Java.
I am using the db2java.zip which is on the same CD with the DB2 v 7.2.
My input is a java.io.Reader, so the question is what should I do in order to write to a CLOB field. The OS is Windows NT.
My current work around is to create a file, on the disk, from the java.io.Reader, open an FileInputStream on the temporary file and use the PreparedStatement.setAsciiStream method. Of course this is not acceptable from the performances point of view.
During my searches on ibm.com I found the class com.ibm.as400.access.AS400JDBCBlob,
having methods as setBinaryStream which 'returns a stream that an application can use to write to this BLOB'. It looks that it can serve my purposes, as I can read from my java.io.Reader and write using the returned java.iutputStream.
But, I didn't find anything similar for Windows NT.
Following is the code we are currently use with Oracle.
...............
stmt = con.prepareStatement("INSERT INTO CWMDSegment (Name,SegmentType) values (?,empty_clob()"
stmt.setString(1, name);
stmt.execute ();
stmt.close();
stmt = con.prepareStatement("SELECT Segment FROM CWMDSegment WHERE name=? for update"
stmt.setString(1, name);
rset = stmt.executeQuery();
rset.next();
CLOB blob = ((OracleResultSet)rset).getCLOB(1);
outstream = blob.getCharacterOutputStream();
int size = blob.getBufferSize();
char[] buffer = new char[size];
int length = -1;
while ((length = rd.read(buffer,0,size)) > 0)
outstream.write(buffer, 0, length);
...............