Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing LOBs in java - not implemented?

Status
Not open for further replies.

Nick23

Programmer
Sep 13, 2002
3
CA
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.io_OutputStream.
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);
...............
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top