Am trying to do update a clob column using a connection object that is retrieved using Apache DBCP connection pooling.
Earlier, I've implemented connection pooling using [this][1] and it was working fine i.e am able to update CLOB. I switched to DBCP because I was getting *java.sql.SQLException: ORA-01000: maximum open cursors exceeded*. I've checked connection, resultSet, preparedStatement objects in all the DAOs. All the *finally* blocks have these cursors closed. Still am facing this error and so decided to switch to DBCP.
But, when I try to update CLOB, with this DBCP connection, the application just hangs at *pstmt.executeUpdate()*.
Connection conn = null;
PreparedStatement pstmt = null;
CLOB clob = null;
String q = "UPDATE REPORT_TABLE SET RPT_FILE = ? WHERE RPT_SEQ_NUM = ?";
...
conn = DBConnection.getConnection();
pstmt = conn.prepareStatement(q);
clob = getCLOB(xmlReport, conn);
pstmt.setObject(1, clob);
pstmt.setString(2, reportSeqNo);
if (pstmt.executeUpdate() == 1) {
logger.logError("Report has been successfully UPDATED");
}
...
where getCLOB() method is:
private CLOB getCLOB(String xmlData, Connection conn) throws SQLException{
CLOB tempClob = null;
try{
// If the temporary CLOB has not yet been created, create new
tempClob = CLOB.createTemporary(conn, true, CLOB.DURATION_SESSION);
// Open the temporary CLOB in readwrite mode to enable writing
tempClob.open(CLOB.MODE_READWRITE);
// Get the output stream to write
Writer tempClobWriter = tempClob.getCharacterOutputStream();
// Write the data into the temporary CLOB
tempClobWriter.write(xmlData);
// Flush and close the stream
tempClobWriter.flush();
tempClobWriter.close();
// Close the temporary CLOB
tempClob.close();
} catch(SQLException sqlexp){
tempClob.freeTemporary();
sqlexp.printStackTrace();
} catch(Exception exp){
exp.printStackTrace();
tempClob.freeTemporary();
exp.printStackTrace();
}
return tempClob;
}
I've also tried by passing the `((DelegatingConnection) conn).getInnermostDelegate()` connection, but no use.
Also, I tried what [Shiny][2] has suggested [here][3]. This time its hanging while I'm selecting the data.
Am using Oracle 9i and the JDBC Oracle Driver version is above 10(Sorry, couldn't remember exact version now).
[1]: http://java.sun.com/developer/onlineTraining/Programming/JDCBook/conpool.html
[2]: https://stackoverflow.com/users/7867/mr-shiny-and-new
[3]: https://stackoverflow.com/questions/862355/overcomplicated-oracle-jdbc-blob-handling Could you show your getCLOB method (and what datatype is "xmlReport"?)?
以上就是unable to update CLOB using DBCP connection 的详细内容,更多请关注web前端其它相关文章!