Module java.sql
Package java.sql

Class BatchUpdateException

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

public class BatchUpdateException extends SQLException
在批量更新操作期间发生错误时抛出的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
参见:
  • Constructor Details

    • BatchUpdateException

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

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

      参数:
      reason - 错误的描述
      SQLState - 标识异常的XOPEN或SQL:2003代码
      vendorCode - 特定数据库供应商使用的异常代码
      updateCounts - 一个int数组,每个元素指示批处理中每个SQL命令的更新计数,对于在命令失败后继续处理的JDBC驱动程序,每个SQL命令的更新计数为Statement.SUCCESS_NO_INFOStatement.EXECUTE_FAILED;对于在命令失败后停止处理的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。

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

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

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

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

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

      public BatchUpdateException(int[] updateCounts)
      构造一个使用给定updateCounts初始化的BatchUpdateException对象。通过调用Throwable.initCause(java.lang.Throwable)方法进行初始化。原因和SQL状态初始化为null,供应商代码初始化为0。

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

      参数:
      updateCounts - 一个int数组,每个元素指示批处理中每个SQL命令的更新计数,对于在命令失败后继续处理的JDBC驱动程序,每个SQL命令的更新计数为Statement.SUCCESS_NO_INFOStatement.EXECUTE_FAILED;对于在命令失败后停止处理的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。 如果cause==null,则reason被初始化为null,如果cause!=null,则reason被初始化为cause.toString()
      参数:
      cause - 此SQLException的根本原因(稍后可通过getCause()方法检索);可能为null,表示原因不存在或未知。
      自版本:
      1.6
      参见:
    • BatchUpdateException

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

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

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

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

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

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

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

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

      cause - 此SQLException的根本原因(稍后可通过getCause()方法检索);可能为null,表示原因不存在或未知。
      自版本:
      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数组,每个元素表示批量处理中每个SQL命令的更新计数,对于在命令失败后继续处理的JDBC驱动程序,每个SQL命令的更新计数或Statement.SUCCESS_NO_INFOStatement.EXECUTE_FAILED;对于在命令失败后停止处理的JDBC驱动程序,每个SQL命令的更新计数或Statement.SUCCESS_NO_INFO

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

      cause - 此SQLException的根本原因(稍后可通过getCause()方法检索);可能为null,表示原因不存在或未知。
      自版本:
      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数组,每个元素表示批量处理中每个SQL命令的更新计数,对于在命令失败后继续处理的JDBC驱动程序,每个SQL命令的更新计数或Statement.SUCCESS_NO_INFOStatement.EXECUTE_FAILED;对于在命令失败后停止处理的JDBC驱动程序,每个SQL命令的更新计数或Statement.SUCCESS_NO_INFO
      cause - 此SQLException的根本原因(稍后可通过getCause()方法检索);可能为null,表示原因不存在或未知。
      自版本:
      1.8
  • Method Details

    • 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