wood burning stoves 2.0*
The moose likes JDBC and the fly likes How to update clob field in oracle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to update clob field in oracle" Watch "How to update clob field in oracle" New topic

How to update clob field in oracle

rose deng
Ranch Hand

Joined: Dec 29, 2000
Posts: 78
Could somebody tell me how to update clob field in oracle 8.1.7? I use preparestatement.setString, and get "data size too big" error.
Thanks a lot.
Patrick McDowell

Joined: Aug 15, 2000
Posts: 4
Here's a method I use to update Clob.
public void updateClob(String updateString, int rowID, Connection con)
Statement stmt = null;
PreparedStatement pstmt = null;
ResultSet rs = null;

Clob clob = null;
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT CLOB FROM YOUR_TABLE WHERE ID =" + rowID + " FOR UPDATE OF CLOB");
clob = rs.getClob("CLOB");

OutputStream os = ((oracle.sql.CLOB) clob).getAsciiOutputStream();

byte[] b = updateString.getBytes("ASCII");


pstmt = con.prepareStatement("UPDATE YOUR_TABLE SET CLOB = ? WHERE ID = " + rowID);

pstmt.setClob(1, clob);
catch(Exception e)
//log error
catch(Exception e)
//log error
[ September 16, 2002: Message edited by: Patrick McDowell ]
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

You might be interested in these Oracle resources to help you:
Oracle9i JDBC Developer's Guide and Reference( great tutorial using Oracle/JDBC )
loads of Oracle JDBC sample code
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: How to update clob field in oracle
Similar Threads
help: lock problem during Clob update
Question on update CLOB column when the column value is null
updating a CLOB field using oracle
Pls give me solution to solve "String literal too long" problem:
hanging while inserting CLOB