以下代码段失败,其中包含Map Size的基础异常 订单为30K +
如何在不违反游标限制的情况下完成此操作?
orclSQLDevDB=DBConnector.getOracleDevDB();
for (Map.Entry<String, String> entry : issueMapMSRB2.entrySet()) {
orclSQLDevDB.setAutoCommit(false);
PreparedStatement psORACLE = orclSQLDevDB
.prepareStatement(NamedQueries.oracle_INSERT);
psORACLE.setString(1, entry.getKey());
psORACLE.setString(2, "NMDF");
if (issueMapMSRB2.get(entry.getKey()).contains("_O_"))
psORACLE.setString(3, "ORACLE");
else
psORACLE.setString(3, "MSSQL");
psORACLE.setString(4, issueMapMSRB2.get(entry.getKey()));
psORACLE.executeUpdate(); // FAILURE LINE.
orclSQLDevDB.commit();
}
异常堆栈跟踪
16 Jan 2015 14:52:26,540 [main] ERROR RunAnalytics: [Oracle Dev DB]-ORA-01000: maximum open cursors exceeded
java.sql.SQLException: ORA-01000: maximum open cursors exceeded
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:440)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:837)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:445)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:191)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:523)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1010)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1315)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3576)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3657)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1350)
at com.citi.Analytics.RunAnalytics.dumpResultToOracle(RunAnalytics.java:218)
at com.citi.Analytics.RunAnalytics.main(RunAnalytics.java:125)
答案 0 :(得分:3)
您不需要在循环中定义PreparedStatement。把它带出循环,然后setAutoCommit再试一次。您还需要确保关闭PreparedStatement。您应该使用try-catch-finally
并在finally
。
以下是Oracle的一个很好的例子:Using Prepared Statements
答案 1 :(得分:2)
当你完成使用它之后,你需要关闭你的'Connection'
,这就是为什么你要打开之前已经关闭的许多游标的原因。
答案 2 :(得分:2)
关闭语句,永远不要准备内部循环。