JDBC 更大容量的更新失败 Collections?
JDBC Update failing for larger volume Collections?
下面的代码片段因地图大小的底层异常而失败
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)
您不需要在循环中定义 PreparedStatement。将其从循环中取出,然后 setAutoCommit 再试一次。您还需要确保关闭 PreparedStatement。您应该使用 try-catch-finally
并在 finally
.
中关闭它
这是来自 Oracle 的一个很好的例子:Using Prepared Statements
您需要在使用完 'Connection'
后关闭它,这就是为什么您会打开许多之前未关闭的游标。
关闭语句并且从不准备内部循环。
下面的代码片段因地图大小的底层异常而失败 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)
您不需要在循环中定义 PreparedStatement。将其从循环中取出,然后 setAutoCommit 再试一次。您还需要确保关闭 PreparedStatement。您应该使用 try-catch-finally
并在 finally
.
这是来自 Oracle 的一个很好的例子:Using Prepared Statements
您需要在使用完 'Connection'
后关闭它,这就是为什么您会打开许多之前未关闭的游标。
关闭语句并且从不准备内部循环。