This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes CLOB field in Oracle not being updated with JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "CLOB field in Oracle not being updated with JDBC" Watch "CLOB field in Oracle not being updated with JDBC" New topic

CLOB field in Oracle not being updated with JDBC

Susan Mincey

Joined: Nov 08, 2007
Posts: 13
I have tried about 6 different methods to insert my form field (>4000 characters) into my CLOB field in Oracle but nothing is working. I have used oracle.sql.CLOB and java.sql.Clob. I have used a Writer to stream by characters to the CLob object, I have used setString() from java.sql.Clob but it is still not inserting the Lob locator into the DB, nor any of the actual data. I have copied code from several posters in Java Ranch and other places but nothing is doing the trick. Can anyone offer advice or corrections? Here's the
code: (java 1.4, Oracle 10g, ojdbc14.jar)

This part works:
connect to DB with JDBC
insert empty_Clob() and row identifier


String sql = "SELECT body FROM table "
+ "WHERE id = '1'";

ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
//oracle.sql.CLOB clob = null;
java.sql.Clob myClob = null;
if (
//clob = (oracle.sql.CLOB)rs.getClob("body");
myClob = (java.sql.Clob)rs.getClob("body");
plog.log("log sql here: " + sql);

This part does not:

// wr = ((oracle.sql.CLOB)clob).getCharacterOutputStream(); //this is deprecated method for oracle.sql.CLOB wr = ((java.sql.Clob)myClob).setCharacterStream(1);

char[] aClobData = formFieldText.toCharArray();
wr.write (aClobData);
wr.flush ();
wr.close ();
rs.close ();
} else{
plog.log("CLOB not updated in DB:" + sql);
//close all connections here.....
// commit DB here....

There seems to be a dozen ways to stream data to the Clob object but I haven't found one that works. Does anyone have something that works? Thanks
jQuery in Action, 3rd edition
subject: CLOB field in Oracle not being updated with JDBC
It's not a secret anymore!