KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > sql > BatchUpdateException


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
8 package java.sql;
9
10 /**
11  * An exception thrown when an error
12  * occurs during a batch update operation. In addition to the
13  * information provided by {@link SQLException}, a
14  * <code>BatchUpdateException</code> provides the update
15  * counts for all commands that were executed successfully during the
16  * batch update, that is, all commands that were executed before the error
17  * occurred. The order of elements in an array of update counts
18  * corresponds to the order in which commands were added to the batch.
19  * <P>
20  * After a command in a batch update fails to execute properly
21  * and a <code>BatchUpdateException</code> is thrown, the driver
22  * may or may not continue to process the remaining commands in
23  * the batch. If the driver continues processing after a failure,
24  * the array returned by the method
25  * <code>BatchUpdateException.getUpdateCounts</code> will have
26  * an element for every command in the batch rather than only
27  * elements for the commands that executed successfully before
28  * the error. In the case where the driver continues processing
29  * commands, the array element for any command
30  * that failed is <code>Statement.EXECUTE_FAILED</code>.
31  * <P>
32  * @since 1.2
33  */

34
35 public class BatchUpdateException extends SQLException JavaDoc {
36
37   /**
38    * Constructs a fully-specified <code>BatchUpdateException</code> object,
39    * initializing it with the given values.
40    * @param reason a description of the error
41    * @param SQLState an X/OPEN code identifying the error
42    * @param vendorCode an exception code used by a particular
43    * database vendor
44    * @param updateCounts an array of <code>int</code>, with each element
45    * indicating the update count for a SQL command that executed
46    * successfully before the exception was thrown
47    * @since 1.2
48    */

49   public BatchUpdateException( String JavaDoc reason, String JavaDoc SQLState, int vendorCode,
50                    int[] updateCounts ) {
51     super(reason, SQLState, vendorCode);
52     this.updateCounts = updateCounts;
53   }
54
55   /**
56    * Constructs a <code>BatchUpdateException</code> initialized with
57    * the given arguments (<code>reason</code>,
58    * <code>SQLState</code>, and <code>updateCounts</code>) and 0 for the vendor
59    * code.
60    * @param reason a description of the exception
61    * @param SQLState an X/OPEN code identifying the exception
62    * @param updateCounts an array of <code>int</code>, with each element
63    * indicating the update count for a SQL command that executed
64    * successfully before the exception was thrown
65    * @since 1.2
66    */

67   public BatchUpdateException(String JavaDoc reason, String JavaDoc SQLState,
68                   int[] updateCounts) {
69     super(reason, SQLState);
70     this.updateCounts = updateCounts;
71   }
72
73   /**
74    * Constructs a <code>BatchUpdateException</code> initialized with
75    * <code>reason</code>, <code>updateCounts</code> and <code>null</code>
76    * for the SQLState and 0 for the vendorCode.
77    * @param reason a description of the exception
78    * @param updateCounts an array of <code>int</code>, with each element
79    * indicating the update count for a SQL command that executed
80    * successfully before the exception was thrown
81    * @since 1.2
82    */

83   public BatchUpdateException(String JavaDoc reason, int[] updateCounts) {
84     super(reason);
85     this.updateCounts = updateCounts;
86   }
87
88   /**
89    * Constructs a <code>BatchUpdateException</code> initialized to
90    * <code>null</code> for the reason and SQLState and 0 for the
91    * vendor code.
92    * @param updateCounts an array of <code>int</code>, with each element
93    * indicating the update count for a SQL command that executed
94    * successfully before the exception was thrown
95    * @since 1.2
96    */

97   public BatchUpdateException(int[] updateCounts) {
98     super();
99     this.updateCounts = updateCounts;
100   }
101
102   /**
103    * Constructs a <code>BatchUpdateException</code> object
104    * with the reason, SQLState, and update count initialized to
105    * <code>null</code> and the vendor code initialized to 0.
106    * @since 1.2
107    */

108   public BatchUpdateException() {
109     super();
110     this.updateCounts = null;
111   }
112
113   /**
114    * Retrieves the update count for each update statement in the batch
115    * update that executed successfully before this exception occurred.
116    * A driver that implements batch updates may or may not continue to
117    * process the remaining commands in a batch when one of the commands
118    * fails to execute properly. If the driver continues processing commands,
119    * the array returned by this method will have as many elements as
120    * there are commands in the batch; otherwise, it will contain an
121    * update count for each command that executed successfully before
122    * the <code>BatchUpdateException</code> was thrown.
123    *<P>
124    * The possible return values for this method were modified for
125    * the Java 2 SDK, Standard Edition, version 1.3. This was done to
126    * accommodate the new option of continuing to process commands
127    * in a batch update after a <code>BatchUpdateException</code> object
128    * has been thrown.
129    *
130    * @return an array of <code>int</code> containing the update counts
131    * for the updates that were executed successfully before this error
132    * occurred. Or, if the driver continues to process commands after an
133    * error, one of the following for every command in the batch:
134    * <OL>
135    * <LI>an update count
136    * <LI><code>Statement.SUCCESS_NO_INFO</code> to indicate that the command
137    * executed successfully but the number of rows affected is unknown
138    * <LI><code>Statement.EXECUTE_FAILED</code> to indicate that the command
139    * failed to execute successfully
140    * </OL>
141    * @since 1.3
142    */

143   public int[] getUpdateCounts() {
144     return updateCounts;
145   }
146
147   /**
148    * The array that describes the outcome of a batch execution.
149    * @serial
150    * @since 1.2
151    */

152   private int[] updateCounts;
153 }
154
Popular Tags