java.sql.SQLException:语句在调用executeBatch()

时间:2019-01-24 13:55:36

标签: java oracle jdbc

使用准备好的语句addBatch()添加并使用executeBatch()执行的记录有数百万条,并且会引发如下错误。

  

java.sql.SQLException:语句已经关闭           在weblogic.jdbc.wrapper.Statement.checkStatement(Statement.java:318)           在weblogic.jdbc.wrapper.Statement.preInvocationHandler(Statement.java:123)           在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();
    }

}

}

0 个答案:

没有答案
相关问题