problem with inserting a blob (urgent)
hi,
i am trying to insert a blob and clob into the oracle db. both are read correctly but when i try to write them, exceptions are thrown. here is the code.
// function to insert a clob
public void writeCLOB(long contentId, String meta, Connection con) {
String data = null;
PreparedStatement ps = null;
ResultSet rs = null;
CLOB clob = null;
String stmt = null;
try {
if (meta == null || meta.length() == 0) {
stmt = "update content set metadataxml = empty_clob() where contentid = ? ";
ps = con.prepareStatement(stmt);
ps.setLong(1, contentId);
ps.executeUpdate();
return;
}
stmt = "select metadataxml from content where contentid = ? for update";
ps = con.prepareStatement(stmt, ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ps.setLong(1, contentId);
rs = ps.executeQuery();
if (rs.next()) {
clob = ((OracleResultSet) rs).getCLOB(1);
Writer w = clob.getCharacterOutputStream();
w.write(meta);
w.close();
}
rs.close();
ps.close();
} catch (SQLException sqe) {
System.out.println ("Exception in writeCLOB() :");
sqe.printStackTrace();
} catch (IOException ioe) {
System.out.println ("Exception in writeCLOB() :");
ioe.printStackTrace();
}
}
and here are the exceptions:
Exception in writeBLOB() :
java.sql.SQLException: ORA-01002: fetch out of sequence
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1405)
at oracle.jdbc.ttc7.TTC7Protocol.fetch(TTC7Protocol.java:889)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:1681)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1870)
at oracle.jdbc.driver.OraclePreparedStatement.doScrollPstmtExecuteUpdate(OraclePreparedStatement.java:3015)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:385)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:314)
at iac.tango.app.TestClob.writeBLOB(TestClob.java:140)
at iac.tango.app.TestClob.main(TestClob.java:175)
however the read methods work well, please help me.
thanx in advance,
amt

