File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes JDBC Update example using empty_clob() function Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC Update example using empty_clob() function" Watch "JDBC Update example using empty_clob() function" New topic
Author

JDBC Update example using empty_clob() function

Stuart Bell
Greenhorn

Joined: Sep 17, 2004
Posts: 22
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


SCJP (Java 2)<br />SCJD<br />SCWCD
Prashant Jain
Greenhorn

Joined: Aug 19, 2004
Posts: 29
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

Joined: Aug 19, 2004
Posts: 29
For updating the clob you could first obtain a reference to the clob and then use the above code to reset it.
 
 
subject: JDBC Update example using empty_clob() function