• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

CLOB field in Oracle not being updated with JDBC

 
Greenhorn
Posts: 13
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

try
{

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

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

This part does not:

// java.io.Writer wr = ((oracle.sql.CLOB)clob).getCharacterOutputStream(); //this is deprecated method for oracle.sql.CLOB
java.io.Writer 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic