Существуют миллионы записей, которые добавляются с использованием подготовленного оператора addBatch()
и выполняются с использованием executeBatch()
, и выдается ошибка, как показано ниже.
java.sql.SQLException: оператор уже закрыт
на weblogic.jdbc.wrapper.Statement.checkStatement (Statement.java:318)
на weblogic.jdbc.wrapper.Statement.preInvocationHandler (Statement.java:123)
at weblogic.jdbc.wrapper.PreparedStatement.executeBatch (PreparedStatement.java:188)
Как видно из вышесказанного, мы видим, что это происходит во время звонка на executeBatch()
- PreparedStatement
.
Что можно сделать, чтобы преодолеть это?
Попробовал setQueryTimeout
- не помогло.
код -
//function123 called by parent function.
//Argument -1 "Connection conn" - spent considerable amount of time in previous methods
//Argument -2 "List plans" - The list has around a million records(plans)
//
private void function123(Connection conn, List plans) throws Exception {
//Connection opened from parent function..
//It is expected to load data in multiple tables and connection has to be retained until all tables gets loaded.
try {
// Create the Prepared Statement for the Insert SQL created
ppdBatchStmt = new AREPreparedStatement(conn, SQL);
for (Iterator A = plans.iterator(); A.hasNext();) {
ppdBatchStmt.setString(2, ...);
ppdBatchStmt.setLong(3, ...);
ppdBatchStmt.setString(4, ...);
ppdBatchStmt.setDouble(5, ...);
.....
....
....
ppdBatchStmt.addBatch();
}
// Execute the prepared Statement
int[] insertedRows = ppdBatchStmt.executeBatch();
catch (RuntimeException runEx) {
} finally {
if (ppdBatchStmt != null) ppdBatchStmt.close();
}
}
}