• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC Update example using empty_clob() function

 
Stuart Bell
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,


I have an interesting problem relating to CLOB usage in an Oracle 8i table. I am writing a large string of data to this column and whenever we are writing something shorter than the original text, it doesn't overwrite the remaining existing text.

I know that the solution is to use empty_clob(), however I can't find any examples of this when using an update statement. Can anyone please help?

Many thanks.


Stuart
 
Prashant Jain
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This should get you going. I am leaving all the error handling and null checks etc. for you.

***************************************************************************
Connection conn;
Clob tempClob;
String ClobData="";//This is what your clob data is going to be.

tempClob = CLOB.createTemporary((Connection) getConnection.invoke(Conn, new Object[0]),false, CLOB.DURATION_SESSION);

// Create a new temporary CLOB.
tempClob = CLOB.createTemporary(Conn,false, CLOB.DURATION_SESSION);

// Open the temporary CLOB in readwrite mode to enable writing.
tempClob.open(CLOB.MODE_READWRITE);

// Get the output stream.
tempClobWriter = tempClob.getCharacterOutputStream();

// Write the data into the temporary CLOB.
tempClobWriter.write(ClobData);
tempClobWriter.flush();

if (tempClob != null) {
tempClob.freeTemporary();
}
************************************************************************

regards
Prashant Jain
 
Prashant Jain
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For updating the clob you could first obtain a reference to the clob and then use the above code to reset it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic