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