• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JDBC Update example using empty_clob() function

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic