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

[2568 byte] By [amtanoli] at [2007-9-26 4:01:56]
# 1
Hi,look at the following topic. http://forum.java.sun.com/thread.jsp?forum=31&thread=159929Hope it helps you,Martin
edosoft at 2007-6-29 12:58:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

I have seen this error caused by "select...for update" before. Before you "select...for update" set the connection.setAutocommit(false). after the transactionis complete, connection.setAutocommit(true).

link:

http://otn.oracle.com/tech/java/sqlj_jdbc/htdocs/jdbc_faq.htm#_18_

Hope this helps,

Jamie

jlrober at 2007-6-29 12:58:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...