模块 java.sql
 java.sql

类 BatchUpdateException

所有已实现的接口:
Serializable , Iterable<Throwable>

public class BatchUpdateException extends SQL异常
SQLException 的子类在批量更新操作期间发生错误时抛出。除了 SQLException 提供的信息外,BatchUpdateException 还提供了在批量更新期间成功执行的所有命令的更新计数,即发生错误之前执行的所有命令。更新计数数组中元素的顺序对应于将命令添加到批处理的顺序。

在批处理更新中的命令无法正确执行并抛出 BatchUpdateException 后,驱动程序可能会也可能不会继续处理批处理中的剩余命令。如果驱动程序在失败后继续处理,方法 BatchUpdateException.getUpdateCounts 返回的数组将包含批处理中每个命令的元素,而不仅仅是错误前成功执行的命令的元素。在驱动程序继续处理命令的情况下,任何失败命令的数组元素都是 Statement.EXECUTE_FAILED

JDBC 驱动程序实现应使用构造函数 BatchUpdateException(String reason, String SQLState, int vendorCode, long []updateCounts, Throwable cause) 而不是采用 int[] 作为更新计数的构造函数以避免溢出的可能性。

如果调用 Statement.executeLargeBatch 方法,建议调用 getLargeUpdateCounts 而不是 getUpdateCounts 以避免整数更新计数可能溢出。

自从:
1.2
参见:
  • 构造方法详细信息

    • BatchUpdateException

      public BatchUpdateException(String  reason, String  SQLState, int vendorCode, int[] updateCounts)
      构造一个用给定的 reasonSQLStatevendorCodeupdateCounts 初始化的 BatchUpdateException 对象。 cause 未初始化,随后可能会通过调用 Throwable.initCause(java.lang.Throwable) 方法进行初始化。

      Note: 没有对 updateCounts 进行溢出验证,因此建议您使用构造函数 BatchUpdateException(String reason, String SQLState, int vendorCode, long []updateCounts, Throwable cause)

      参数:
      reason - 错误描述
      SQLState - 标识异常的 XOPEN 或 SQL:2003 代码
      vendorCode - 特定数据库供应商使用的异常代码
      updateCounts - int 的数组,每个元素指示更新计数,Statement.SUCCESS_NO_INFOStatement.EXECUTE_FAILED 用于批处理中的每个 SQL 命令,用于在命令失败后继续处理的 JDBC 驱动程序;对于在命令失败后停止处理的 JDBC 驱动程序,失败前批处理中每个 SQL 命令的更新计数或 Statement.SUCCESS_NO_INFO
      自从:
      1.2
      参见:
    • BatchUpdateException

      public BatchUpdateException(String  reason, String  SQLState, int[] updateCounts)
      构造一个用给定的 reasonSQLStateupdateCounts 初始化的 BatchUpdateException 对象。 cause 未初始化,随后可能会通过调用 Throwable.initCause(java.lang.Throwable) 方法进行初始化。供应商代码初始化为 0。

      Note: 没有对 updateCounts 进行溢出验证,因此建议您使用构造函数 BatchUpdateException(String reason, String SQLState, int vendorCode, long []updateCounts, Throwable cause)

      参数:
      reason - 异常的描述
      SQLState - 标识异常的 XOPEN 或 SQL:2003 代码
      updateCounts - int 的数组,每个元素指示更新计数,Statement.SUCCESS_NO_INFOStatement.EXECUTE_FAILED 用于批处理中的每个 SQL 命令,用于在命令失败后继续处理的 JDBC 驱动程序;对于在命令失败后停止处理的 JDBC 驱动程序,失败前批处理中每个 SQL 命令的更新计数或 Statement.SUCCESS_NO_INFO
      自从:
      1.2
      参见:
    • BatchUpdateException

      public BatchUpdateException(String  reason, int[] updateCounts)
      构造一个用给定的 reasonupdateCounts 初始化的 BatchUpdateException 对象。 cause 未初始化,随后可能会通过调用 Throwable.initCause(java.lang.Throwable) 方法进行初始化。 SQLState 初始化为 null,供应商代码初始化为 0。

      Note: 没有对 updateCounts 进行溢出验证,因此建议您使用构造函数 BatchUpdateException(String reason, String SQLState, int vendorCode, long []updateCounts, Throwable cause)

      参数:
      reason - 异常的描述
      updateCounts - int 的数组,每个元素指示更新计数,Statement.SUCCESS_NO_INFOStatement.EXECUTE_FAILED 用于批处理中的每个 SQL 命令,用于在命令失败后继续处理的 JDBC 驱动程序;对于在命令失败后停止处理的 JDBC 驱动程序,失败前批处理中每个 SQL 命令的更新计数或 Statement.SUCCESS_NO_INFO
      自从:
      1.2
      参见:
    • BatchUpdateException

      public BatchUpdateException(int[] updateCounts)
      构造一个用给定的 updateCounts 初始化的 BatchUpdateException 对象。通过调用 Throwable.initCause(java.lang.Throwable) 方法进行初始化。 reasonSQLState 被初始化为空,供应商代码被初始化为 0。

      Note: 没有对 updateCounts 进行溢出验证,因此建议您使用构造函数 BatchUpdateException(String reason, String SQLState, int vendorCode, long []updateCounts, Throwable cause)

      参数:
      updateCounts - int 的数组,每个元素指示更新计数,Statement.SUCCESS_NO_INFOStatement.EXECUTE_FAILED 用于批处理中的每个 SQL 命令,用于在命令失败后继续处理的 JDBC 驱动程序;对于在命令失败后停止处理的 JDBC 驱动程序,失败前批处理中每个 SQL 命令的更新计数或 Statement.SUCCESS_NO_INFO
      自从:
      1.2
      参见:
    • BatchUpdateException

      public BatchUpdateException()
      构造一个 BatchUpdateException 对象。 reasonSQLStateupdateCounts 被初始化为 null,供应商代码被初始化为 0。cause 没有被初始化,随后可以通过调用 Throwable.initCause(java.lang.Throwable) 方法来初始化。
      自从:
      1.2
      参见:
    • BatchUpdateException

      public BatchUpdateException(Throwable  cause)
      构造一个用给定的 cause 初始化的 BatchUpdateException 对象。 SQLStateupdateCounts 被初始化为 null 并且供应商代码被初始化为 0。 reason 被初始化为 null if cause==nullcause.toString() if cause!=null
      参数:
      cause - 此 SQLException 的根本原因(保存以供以后通过 getCause() 方法检索);可能为空,表示原因不存在或未知。
      自从:
      1.6
      参见:
    • BatchUpdateException

      public BatchUpdateException(int[] updateCounts, Throwable  cause)
      构造一个用给定的 causeupdateCounts 初始化的 BatchUpdateException 对象。 SQLState 初始化为 null,供应商代码初始化为 0。reason 初始化为 null(如果是 cause==null)或cause.toString()(如果是 cause!=null)。

      Note: 没有对 updateCounts 进行溢出验证,因此建议您使用构造函数 BatchUpdateException(String reason, String SQLState, int vendorCode, long []updateCounts, Throwable cause)

      参数:
      updateCounts - int 的数组,每个元素指示更新计数,Statement.SUCCESS_NO_INFOStatement.EXECUTE_FAILED 用于批处理中的每个 SQL 命令,用于在命令失败后继续处理的 JDBC 驱动程序;对于在命令失败后停止处理的 JDBC 驱动程序,失败前批处理中每个 SQL 命令的更新计数或 Statement.SUCCESS_NO_INFO
      cause - 此 SQLException 的根本原因(保存以供以后通过 getCause() 方法检索);可能为空,表示原因不存在或未知。
      自从:
      1.6
      参见:
    • BatchUpdateException

      public BatchUpdateException(String  reason, int[] updateCounts, Throwable  cause)
      构造一个用给定的 reasoncauseupdateCounts 初始化的 BatchUpdateException 对象。 SQLState 初始化为 null,供应商代码初始化为 0。

      Note: 没有对 updateCounts 进行溢出验证,因此建议您使用构造函数 BatchUpdateException(String reason, String SQLState, int vendorCode, long []updateCounts, Throwable cause)

      参数:
      reason - 异常的描述
      updateCounts - int 的数组,每个元素指示更新计数,Statement.SUCCESS_NO_INFOStatement.EXECUTE_FAILED 用于批处理中的每个 SQL 命令,用于在命令失败后继续处理的 JDBC 驱动程序;对于在命令失败后停止处理的 JDBC 驱动程序,失败前批处理中每个 SQL 命令的更新计数或 Statement.SUCCESS_NO_INFO
      cause - 此 SQLException 的根本原因(保存以供以后通过 getCause() 方法检索);可能为空,表示原因不存在或未知。
      自从:
      1.6
      参见:
    • BatchUpdateException

      public BatchUpdateException(String  reason, String  SQLState, int[] updateCounts, Throwable  cause)
      构造一个用给定的 reasonSQLStatecauseupdateCounts 初始化的 BatchUpdateException 对象。供应商代码初始化为 0。
      参数:
      reason - 异常的描述
      SQLState - 标识异常的 XOPEN 或 SQL:2003 代码
      updateCounts - int 的数组,每个元素指示更新计数,Statement.SUCCESS_NO_INFOStatement.EXECUTE_FAILED 用于批处理中的每个 SQL 命令,用于在命令失败后继续处理的 JDBC 驱动程序;对于在命令失败后停止处理的 JDBC 驱动程序,失败前批处理中每个 SQL 命令的更新计数或 Statement.SUCCESS_NO_INFO

      Note: 没有对 updateCounts 进行溢出验证,因此建议您使用构造函数 BatchUpdateException(String reason, String SQLState, int vendorCode, long []updateCounts, Throwable cause)

      cause - 此 SQLException 的根本原因(保存以供以后通过 getCause() 方法检索);可能为空,表示原因不存在或未知。
      自从:
      1.6
      参见:
    • BatchUpdateException

      public BatchUpdateException(String  reason, String  SQLState, int vendorCode, int[] updateCounts, Throwable  cause)
      构造一个用给定的 reasonSQLStatevendorCodecauseupdateCounts 初始化的 BatchUpdateException 对象。
      参数:
      reason - 错误描述
      SQLState - 标识异常的 XOPEN 或 SQL:2003 代码
      vendorCode - 特定数据库供应商使用的异常代码
      updateCounts - int 的数组,每个元素指示更新计数,Statement.SUCCESS_NO_INFOStatement.EXECUTE_FAILED 用于批处理中的每个 SQL 命令,用于在命令失败后继续处理的 JDBC 驱动程序;对于在命令失败后停止处理的 JDBC 驱动程序,失败前批处理中每个 SQL 命令的更新计数或 Statement.SUCCESS_NO_INFO

      Note: 没有对 updateCounts 进行溢出验证,因此建议您使用构造函数 BatchUpdateException(String reason, String SQLState, int vendorCode, long []updateCounts, Throwable cause)

      cause - 此 SQLException 的根本原因(保存以供以后通过 getCause() 方法检索);可能为空,表示原因不存在或未知。
      自从:
      1.6
      参见:
    • BatchUpdateException

      public BatchUpdateException(String  reason, String  SQLState, int vendorCode, long[] updateCounts, Throwable  cause)
      构造一个用给定的 reasonSQLStatevendorCodecauseupdateCounts 初始化的 BatchUpdateException 对象。

      当返回的更新计数可能超过 Integer.MAX_VALUE 时,应使用此构造函数。

      参数:
      reason - 错误描述
      SQLState - 标识异常的 XOPEN 或 SQL:2003 代码
      vendorCode - 特定数据库供应商使用的异常代码
      updateCounts - long 的数组,每个元素指示更新计数,Statement.SUCCESS_NO_INFOStatement.EXECUTE_FAILED 用于 JDBC 驱动程序在命令失败后继续处理的批处理中的每个 SQL 命令;对于在命令失败后停止处理的 JDBC 驱动程序,失败前批处理中每个 SQL 命令的更新计数或 Statement.SUCCESS_NO_INFO
      cause - 此 SQLException 的根本原因(保存以供以后通过 getCause() 方法检索);可能为空,表示原因不存在或未知。
      自从:
      1.8
  • 方法详情

    • getUpdateCounts

      public int[] getUpdateCounts()
      检索在发生此异常之前成功执行的批量更新中每个更新语句的更新计数。当其中一个命令未能正确执行时,实现批量更新的驱动程序可能会或可能不会继续处理批处理中的其余命令。如果驱动程序继续处理命令,则此方法返回的数组将包含与批处理中的命令一样多的元素;否则,它将包含在抛出 BatchUpdateException 之前成功执行的每个命令的更新计数。

      此方法的可能返回值已针对 Java 2 SDK,标准版,版本 1.3 进行了修改。这样做是为了适应在抛出 BatchUpdateException 对象后继续处理批量更新中的命令的新选项。

      返回:
      一个 int 数组,其中包含在此错误发生之前成功执行的更新的更新计数。或者,如果驱动程序在出错后继续处理命令,则批处理中的每个命令都执行以下操作之一:
      1. 更新计数
      2. Statement.SUCCESS_NO_INFO 表示命令执行成功但受影响的行数未知
      3. Statement.EXECUTE_FAILED表示命令未能成功执行
      自从:
      1.3
      参见:
    • getLargeUpdateCounts

      public long[] getLargeUpdateCounts()
      检索在发生此异常之前成功执行的批量更新中每个更新语句的更新计数。当其中一个命令未能正确执行时,实现批量更新的驱动程序可能会或可能不会继续处理批处理中的其余命令。如果驱动程序继续处理命令,则此方法返回的数组将包含与批处理中的命令一样多的元素;否则,它将包含在抛出 BatchUpdateException 之前成功执行的每个命令的更新计数。

      当调用 Statement.executeLargeBatch 并且返回的更新计数可能超过 Integer.MAX_VALUE 时,应使用此方法。

      返回:
      一个 long 数组,其中包含在发生此错误之前成功执行的更新的更新计数。或者,如果驱动程序在出错后继续处理命令,则批处理中的每个命令都执行以下操作之一:
      1. 更新计数
      2. Statement.SUCCESS_NO_INFO 表示命令执行成功但受影响的行数未知
      3. Statement.EXECUTE_FAILED表示命令未能成功执行
      自从:
      1.8