BatchUpdateException: the batch will not terminate

前端 未结 4 962
不知归路
不知归路 2020-12-16 20:36

I have an application which processes a very large file and sends data to an oracle database (using Java 6, oracle 9).

In a loop, I use a PreparedStatement ps

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-16 21:11

    there is a workaround that would allow you to use the batch feature. Instead of executing a simple INSERT statement, you can execute a PL/SQL block that will deal with the error appropriately:

    BEGIN
       INSERT INTO your_table VALUES (?,?,...?);
    EXCEPTION
       WHEN OTHERS THEN
          /* deal with the error. For example, log the error id and error msg 
             so that you can list them after the batch */
          INSERT INTO error_table VALUES (?, sqlerrm);
    END
    

    The performance should be on par with the batch insert (should be faster than individual execution of the statements). You could also call a stored procedure instead of a PL/SQL block.

提交回复
热议问题