File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes an example to insert data into Oracle Clob Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "an example to insert data into Oracle Clob" Watch "an example to insert data into Oracle Clob" New topic

an example to insert data into Oracle Clob

holly wang

Joined: Aug 28, 2003
Posts: 13
For theory backgroud:
Step1. Insert empty_clob() into the Clob column of Oracle
Step2. Set autocommit to false
Step3. Select Clob as oracle.sql.CLOB from database
Step4. Insert String into Clob
Step5. Commit

I use Oracle 9i and Java 1.4, JDBC 9i, friend also test above code on Oracle 8i with Java 1.2, hope this helps.
Mostafa Mirzayi

Joined: Feb 25, 2012
Posts: 1
Thank you.
Martin Vajsar

Joined: Aug 22, 2010
Posts: 3728

Please note that this was posted many years ago. The procedure is still valid in newer Oracle versions, though it could use a few modifications:

1) Step two should come first. This way it is commiting the insert of an empty clob. Depending on other circumstances, that might not hurt, but since the intent is to insert a populated clob, it should all happen in one transaction. (The code does it this way actually, only the summary is wrong.)

2) I'd emphasize the need to select for update in step three (again, it is done in the code, but not mentioned in the summary). However, when it actually is just one transaction, the select for update is not needed, as the row is already locked (but it doesn't hurt).

Oracle's own documentation is also a good source if you need to clear more doubts about Oracle's LOBs.
I agree. Here's the link:
subject: an example to insert data into Oracle Clob
jQuery in Action, 3rd edition