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