Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

an example to insert data into Oracle Clob

 
holly wang
Greenhorn
Posts: 13
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For theory backgroud:
http://download-west.oracle.com/docs/cd/B10501_01/java.920/a96654/oralob.htm#1000888
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
Example:

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
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic