OSDN Git Service

Start of AWT merge with Classpath:
[pf3gnuchains/gcc-fork.git] / libjava / java / sql / SQLException.java
1 /* SQLException.java -- General SQL exception
2    Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10  
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING.  If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
20
21 As a special exception, if you link this library with other files to
22 produce an executable, this library does not by itself cause the
23 resulting executable to be covered by the GNU General Public License.
24 This exception does not however invalidate any other reasons why the
25 executable file might be covered by the GNU General Public License. */
26
27
28 package java.sql;
29
30 /**
31   * This exception is thrown when a database error occurs.
32   *
33   * @author Aaron M. Renn (arenn@urbanophile.com)
34   */
35 public class SQLException extends Exception
36 {
37
38 /*************************************************************************/
39
40 /*
41  * Instance Variables
42  */
43
44 /**
45   * This is the next exception in the chain
46   * @serialized
47   */
48 private SQLException next;
49
50 /**
51   * This is the state of the SQL statement at the time of the error.
52   * @serialized
53   */
54 private String SQLState;
55
56 /**
57   * The vendor error code for this error
58   * @serialized
59   */
60 private int vendorCode;
61
62 /*************************************************************************/
63
64 /**
65   * Static Variables
66   */
67
68 /**
69   * This is the serialization UID for this class
70   */
71 private static final long serialVersionUID = 2135244094396331484L;
72
73 /*************************************************************************/
74
75 /*
76  * Constructors
77  */
78
79 /**
80   * This method initializes a new instance of <code>SQLException</code>
81   * that does not have a descriptive messages and SQL state, and which
82   * has a vendor error code of 0.
83   */
84 public 
85 SQLException()
86 {
87   this(null, null, 0);
88 }
89
90 /*************************************************************************/
91
92 /**
93   * This method initializes a new instance of <code>SQLException</code>
94   * with the specified descriptive error message.  The SQL state of this
95   * instance will be <code>null</code> and the vendor error code will be 0.
96   *
97   * @param message A string describing the nature of the error.
98   */
99 public 
100 SQLException(String message)
101 {
102   this(message, null, 0);
103 }
104
105 /*************************************************************************/
106
107 /**
108   * This method initializes a new instance of <code>SQLException</code>
109   * with the specified descriptive error message and SQL state string.
110   * The vendor error code of this instance will be 0.
111   *
112   * @param message A string describing the nature of the error.
113   * @param SQLState A string containing the SQL state of the error.
114   */
115 public
116 SQLException(String message, String SQLState)
117 {
118   this(message, SQLState, 0);
119 }
120
121 /*************************************************************************/
122
123 /**
124   * This method initializes a nwe instance of <code>SQLException</code>
125   * with the specified descriptive error message, SQL state string, and
126   * vendor code.
127   *
128   * @param message A string describing the nature of the error.
129   * @param SQLState A string containing the SQL state of the error.
130   * @param vendorCode The vendor error code associated with this error.
131   */
132 public
133 SQLException(String message, String SQLState, int vendorCode)
134 {
135   super(message);
136
137   this.SQLState = SQLState;
138   this.vendorCode = vendorCode;
139 }
140
141 /*************************************************************************/
142
143 /*
144  * Instance Methods
145  */
146
147 /**
148   * This method returns the SQLState information associated with this
149   * error.  The value returned is a <code>String</code> which is formatted
150   * using the XOPEN SQL state conventions.
151   *
152   * @return The SQL state, which may be <code>null</code>.
153   */
154 public String
155 getSQLState()
156 {
157   return(SQLState);
158 }
159
160 /*************************************************************************/
161
162 /**
163   * This method returns the vendor specific error code associated with 
164   * this error.
165   *
166   * @return The vendor specific error code associated with this error.
167   */
168 public int
169 getErrorCode()
170 {
171   return(vendorCode);
172 }
173
174 /*************************************************************************/
175
176 /**
177   * This method returns the exception that is chained to this object.
178   *
179   * @return The exception chained to this object, which may be 
180   * <code>null</code>.
181   */
182 public SQLException
183 getNextException()
184 {
185   return(next);
186 }
187
188 /*************************************************************************/
189
190 /**
191   * This method adds a new exception to the end of the chain of exceptions
192   * that are chained to this object.
193   *
194   * @param e The exception to add to the end of the chain.
195   */
196 public void
197 setNextException(SQLException e)
198 {
199   if (e == null)
200     return;
201
202   SQLException list_entry = this;
203   while (list_entry.getNextException() != null)
204     list_entry = list_entry.getNextException();
205
206   list_entry.next = e;
207 }
208
209 } // class SQLException
210