gpt4 book ai didi

java - 有没有办法从executeBatch获取所有错误?

转载 作者:行者123 更新时间:2023-12-01 09:00:24 24 4
gpt4 key购买 nike

有没有办法从executeBatch获取所有错误?

我的意思是,如果我要从一批 100 个错误中得到 10 个错误,我如何才能在 executeBatch 执行中知道它们?

最佳答案

第一个错误将抛出 BatchUpdateException这将停止批处理过程。

你可以在文档中看到

The subclass of SQLException thrown when an error occurs during a batch update operation. In addition to the information provided by SQLException, a BatchUpdateException provides the update counts for all commands that were executed successfully during the batch update, that is, all commands that were executed before the error occurred. The order of elements in an array of update counts corresponds to the order in which commands were added to the batch.

所以批处理将在那里停止。错误之前的每个“查询”都将被执行(按顺序)。其余的将被忽略。

您始终可以重新创建批处理,因为异常中的成功执行计数包含批处理的其余部分

编辑:

前面的陈述有部分错误。该文档还指出,批处理的其余部分可以根据所使用的驱动程序执行

After a command in a batch update fails to execute properly and a BatchUpdateException is thrown, the driver may or may not continue to process the remaining commands in the batch.

您可以找到错误的语句(以测试确认)

In the case where the driver continues processing commands, the array element for any command that failed is Statement.EXECUTE_FAILED.

关于java - 有没有办法从executeBatch获取所有错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41719303/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com