1. /*
  2. * @(#)BatchUpdateException.java 1.23 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.sql;
  8. /**
  9. * An exception thrown when an error
  10. * occurs during a batch update operation. In addition to the
  11. * information provided by {@link SQLException}, a
  12. * <code>BatchUpdateException</code> provides the update
  13. * counts for all commands that were executed successfully during the
  14. * batch update, that is, all commands that were executed before the error
  15. * occurred. The order of elements in an array of update counts
  16. * corresponds to the order in which commands were added to the batch.
  17. * <P>
  18. * After a command in a batch update fails to execute properly
  19. * and a <code>BatchUpdateException</code> is thrown, the driver
  20. * may or may not continue to process the remaining commands in
  21. * the batch. If the driver continues processing after a failure,
  22. * the array returned by the method
  23. * <code>BatchUpdateException.getUpdateCounts</code> will have
  24. * an element for every command in the batch rather than only
  25. * elements for the commands that executed successfully before
  26. * the error. In the case where the driver continues processing
  27. * commands, the array element for any command
  28. * that failed is <code>Statement.EXECUTE_FAILED</code>.
  29. * <P>
  30. * @since 1.2
  31. */
  32. public class BatchUpdateException extends SQLException {
  33. /**
  34. * Constructs a fully-specified <code>BatchUpdateException</code> object,
  35. * initializing it with the given values.
  36. * @param reason a description of the error
  37. * @param SQLState an X/OPEN code identifying the error
  38. * @param vendorCode an exception code used by a particular
  39. * database vendor
  40. * @param updateCounts an array of <code>int</code>, with each element
  41. * indicating the update count for a SQL command that executed
  42. * successfully before the exception was thrown
  43. * @since 1.2
  44. */
  45. public BatchUpdateException( String reason, String SQLState, int vendorCode,
  46. int[] updateCounts ) {
  47. super(reason, SQLState, vendorCode);
  48. this.updateCounts = updateCounts;
  49. }
  50. /**
  51. * Constructs a <code>BatchUpdateException</code> initialized with
  52. * the given arguments (<code>reason</code>,
  53. * <code>SQLState</code>, and <code>updateCounts</code>) and 0 for the vendor
  54. * code.
  55. * @param reason a description of the exception
  56. * @param SQLState an X/OPEN code identifying the exception
  57. * @param updateCounts an array of <code>int</code>, with each element
  58. * indicating the update count for a SQL command that executed
  59. * successfully before the exception was thrown
  60. * @since 1.2
  61. */
  62. public BatchUpdateException(String reason, String SQLState,
  63. int[] updateCounts) {
  64. super(reason, SQLState);
  65. this.updateCounts = updateCounts;
  66. }
  67. /**
  68. * Constructs a <code>BatchUpdateException</code> initialized with
  69. * <code>reason</code>, <code>updateCounts</code> and <code>null</code>
  70. * for the SQLState and 0 for the vendorCode.
  71. * @param reason a description of the exception
  72. * @param updateCounts an array of <code>int</code>, with each element
  73. * indicating the update count for a SQL command that executed
  74. * successfully before the exception was thrown
  75. * @since 1.2
  76. */
  77. public BatchUpdateException(String reason, int[] updateCounts) {
  78. super(reason);
  79. this.updateCounts = updateCounts;
  80. }
  81. /**
  82. * Constructs a <code>BatchUpdateException</code> initialized to
  83. * <code>null</code> for the reason and SQLState and 0 for the
  84. * vendor code.
  85. * @param updateCounts an array of <code>int</code>, with each element
  86. * indicating the update count for a SQL command that executed
  87. * successfully before the exception was thrown
  88. * @since 1.2
  89. */
  90. public BatchUpdateException(int[] updateCounts) {
  91. super();
  92. this.updateCounts = updateCounts;
  93. }
  94. /**
  95. * Constructs a <code>BatchUpdateException</code> object
  96. * with the reason, SQLState, and update count initialized to
  97. * <code>null</code> and the vendor code initialized to 0.
  98. * @since 1.2
  99. */
  100. public BatchUpdateException() {
  101. super();
  102. this.updateCounts = null;
  103. }
  104. /**
  105. * Retrieves the update count for each update statement in the batch
  106. * update that executed successfully before this exception occurred.
  107. * A driver that implements batch updates may or may not continue to
  108. * process the remaining commands in a batch when one of the commands
  109. * fails to execute properly. If the driver continues processing commands,
  110. * the array returned by this method will have as many elements as
  111. * there are commands in the batch; otherwise, it will contain an
  112. * update count for each command that executed successfully before
  113. * the <code>BatchUpdateException</code> was thrown.
  114. *<P>
  115. * The possible return values for this method were modified for
  116. * the Java 2 SDK, Standard Edition, version 1.3. This was done to
  117. * accommodate the new option of continuing to process commands
  118. * in a batch update after a <code>BatchUpdateException</code> object
  119. * has been thrown.
  120. *
  121. * @return an array of <code>int</code> containing the update counts
  122. * for the updates that were executed successfully before this error
  123. * occurred. Or, if the driver continues to process commands after an
  124. * error, one of the following for every command in the batch:
  125. * <OL>
  126. * <LI>an update count
  127. * <LI><code>Statement.SUCCESS_NO_INFO</code> to indicate that the command
  128. * executed successfully but the number of rows affected is unknown
  129. * <LI><code>Statement.EXECUTE_FAILED</code> to indicate that the command
  130. * failed to execute successfully
  131. * </OL>
  132. * @since 1.3
  133. */
  134. public int[] getUpdateCounts() {
  135. return updateCounts;
  136. }
  137. /**
  138. * The array that describes the outcome of a batch execution.
  139. * @serial
  140. * @since 1.2
  141. */
  142. private int[] updateCounts;
  143. }