1 |
/* SQLException.java -- General SQL exception |
/* SQLException.java -- General SQL exception |
2 |
Copyright (C) 1999, 2000 Free Software Foundation, Inc. |
Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
7 |
it under the terms of the GNU General Public License as published by |
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) |
the Free Software Foundation; either version 2, or (at your option) |
9 |
any later version. |
any later version. |
10 |
|
|
11 |
GNU Classpath is distributed in the hope that it will be useful, but |
GNU Classpath is distributed in the hope that it will be useful, but |
12 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
39 |
package java.sql; |
package java.sql; |
40 |
|
|
41 |
/** |
/** |
42 |
* This exception is thrown when a database error occurs. |
* This exception is thrown when a database error occurs. This exception |
43 |
* |
* keeps track of additional information:<br><ul> |
44 |
* @author Aaron M. Renn (arenn@urbanophile.com) |
* <li>The error message string (part of all Throwables)</li> |
45 |
*/ |
* <li>An "SQLstate" string, following either the XOPEN SQLstate or the SQL 99 |
46 |
public class SQLException extends Exception |
* conventions.</li> |
47 |
{ |
* <li>A vendor-specific integer error code.</li> |
48 |
|
* <li>A chain to the next exception.</li> |
49 |
/*************************************************************************/ |
* <ul> |
50 |
|
* |
51 |
/* |
* @author Aaron M. Renn (arenn@urbanophile.com) |
52 |
* Instance Variables |
* @status updated to 1.4 |
53 |
*/ |
*/ |
54 |
|
public class SQLException extends Exception |
|
/** |
|
|
* This is the next exception in the chain |
|
|
* @serialized |
|
|
*/ |
|
|
private SQLException next; |
|
|
|
|
|
/** |
|
|
* This is the state of the SQL statement at the time of the error. |
|
|
* @serialized |
|
|
*/ |
|
|
private String SQLState; |
|
|
|
|
|
/** |
|
|
* The vendor error code for this error |
|
|
* @serialized |
|
|
*/ |
|
|
private int vendorCode; |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* Static Variables |
|
|
*/ |
|
|
|
|
|
/** |
|
|
* This is the serialization UID for this class |
|
|
*/ |
|
|
private static final long serialVersionUID = 2135244094396331484L; |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/* |
|
|
* Constructors |
|
|
*/ |
|
|
|
|
|
/** |
|
|
* This method initializes a new instance of <code>SQLException</code> |
|
|
* that does not have a descriptive messages and SQL state, and which |
|
|
* has a vendor error code of 0. |
|
|
*/ |
|
|
public |
|
|
SQLException() |
|
|
{ |
|
|
this(null, null, 0); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method initializes a new instance of <code>SQLException</code> |
|
|
* with the specified descriptive error message. The SQL state of this |
|
|
* instance will be <code>null</code> and the vendor error code will be 0. |
|
|
* |
|
|
* @param message A string describing the nature of the error. |
|
|
*/ |
|
|
public |
|
|
SQLException(String message) |
|
|
{ |
|
|
this(message, null, 0); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method initializes a new instance of <code>SQLException</code> |
|
|
* with the specified descriptive error message and SQL state string. |
|
|
* The vendor error code of this instance will be 0. |
|
|
* |
|
|
* @param message A string describing the nature of the error. |
|
|
* @param SQLState A string containing the SQL state of the error. |
|
|
*/ |
|
|
public |
|
|
SQLException(String message, String SQLState) |
|
|
{ |
|
|
this(message, SQLState, 0); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method initializes a nwe instance of <code>SQLException</code> |
|
|
* with the specified descriptive error message, SQL state string, and |
|
|
* vendor code. |
|
|
* |
|
|
* @param message A string describing the nature of the error. |
|
|
* @param SQLState A string containing the SQL state of the error. |
|
|
* @param vendorCode The vendor error code associated with this error. |
|
|
*/ |
|
|
public |
|
|
SQLException(String message, String SQLState, int vendorCode) |
|
|
{ |
|
|
super(message); |
|
|
|
|
|
this.SQLState = SQLState; |
|
|
this.vendorCode = vendorCode; |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/* |
|
|
* Instance Methods |
|
|
*/ |
|
|
|
|
|
/** |
|
|
* This method returns the SQLState information associated with this |
|
|
* error. The value returned is a <code>String</code> which is formatted |
|
|
* using the XOPEN SQL state conventions. |
|
|
* |
|
|
* @return The SQL state, which may be <code>null</code>. |
|
|
*/ |
|
|
public String |
|
|
getSQLState() |
|
|
{ |
|
|
return(SQLState); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method returns the vendor specific error code associated with |
|
|
* this error. |
|
|
* |
|
|
* @return The vendor specific error code associated with this error. |
|
|
*/ |
|
|
public int |
|
|
getErrorCode() |
|
|
{ |
|
|
return(vendorCode); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method returns the exception that is chained to this object. |
|
|
* |
|
|
* @return The exception chained to this object, which may be |
|
|
* <code>null</code>. |
|
|
*/ |
|
|
public SQLException |
|
|
getNextException() |
|
|
{ |
|
|
return(next); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* This method adds a new exception to the end of the chain of exceptions |
|
|
* that are chained to this object. |
|
|
* |
|
|
* @param e The exception to add to the end of the chain. |
|
|
*/ |
|
|
public void |
|
|
setNextException(SQLException e) |
|
55 |
{ |
{ |
56 |
if (e == null) |
/** |
57 |
return; |
* Compatible with JDK 1.1+. |
58 |
|
*/ |
59 |
SQLException list_entry = this; |
private static final long serialVersionUID = 2135244094396331484L; |
60 |
while (list_entry.getNextException() != null) |
|
61 |
list_entry = list_entry.getNextException(); |
/** |
62 |
|
* This is the next exception in the chain. |
63 |
list_entry.next = e; |
* |
64 |
} |
* @serial the next exception in the chain |
65 |
|
*/ |
66 |
|
// Package visible for use by SQLWarning. |
67 |
|
SQLException next; |
68 |
|
|
69 |
|
/** |
70 |
|
* This is the state of the SQL statement at the time of the error. |
71 |
|
* |
72 |
|
* @serial the SQLstate |
73 |
|
*/ |
74 |
|
private final String SQLState; |
75 |
|
|
76 |
|
/** |
77 |
|
* The vendor error code for this error. |
78 |
|
* |
79 |
|
* @serial the vendor code |
80 |
|
*/ |
81 |
|
private final int vendorCode; |
82 |
|
|
83 |
|
/** |
84 |
|
* Create a new instance that does not have a descriptive messages or SQL |
85 |
|
* state, and which has a vendor error code of 0. |
86 |
|
*/ |
87 |
|
public SQLException() |
88 |
|
{ |
89 |
|
this(null, null, 0); |
90 |
|
} |
91 |
|
|
92 |
|
/** |
93 |
|
* Create a new instance with the specified descriptive error message. The |
94 |
|
* SQL state of this instance will be <code>null</code> and the vendor |
95 |
|
* error code will be 0. |
96 |
|
* |
97 |
|
* @param message a string describing the nature of the error |
98 |
|
*/ |
99 |
|
public SQLException(String message) |
100 |
|
{ |
101 |
|
this(message, null, 0); |
102 |
|
} |
103 |
|
|
104 |
|
/** |
105 |
|
* Create a new instance with the specified descriptive error message |
106 |
|
* and SQL state string. The vendor error code of this instance will be 0. |
107 |
|
* |
108 |
|
* @param message a string describing the nature of the error |
109 |
|
* @param SQLState a string containing the SQL state of the error |
110 |
|
*/ |
111 |
|
public SQLException(String message, String SQLState) |
112 |
|
{ |
113 |
|
this(message, SQLState, 0); |
114 |
|
} |
115 |
|
|
116 |
|
/** |
117 |
|
* Create a new instance with the specified descriptive error message, |
118 |
|
* SQL state string, and vendor code. |
119 |
|
* |
120 |
|
* @param message a string describing the nature of the error |
121 |
|
* @param SQLState a string containing the SQL state of the error |
122 |
|
* @param vendorCode the vendor error code associated with this error |
123 |
|
*/ |
124 |
|
public SQLException(String message, String SQLState, int vendorCode) |
125 |
|
{ |
126 |
|
super(message); |
127 |
|
this.SQLState = SQLState; |
128 |
|
this.vendorCode = vendorCode; |
129 |
|
} |
130 |
|
|
131 |
|
/** |
132 |
|
* Get the SQLState information associated with this error. This |
133 |
|
* implementation formats the value using the XOPEN SQL state conventions. |
134 |
|
* |
135 |
|
* @return The SQL state, which may be <code>null</code> |
136 |
|
*/ |
137 |
|
public String getSQLState() |
138 |
|
{ |
139 |
|
return SQLState; |
140 |
|
} |
141 |
|
|
142 |
|
/** |
143 |
|
* Get the vendor specific error code associated with this error. |
144 |
|
* |
145 |
|
* @return the vendor specific error code associated with this error |
146 |
|
*/ |
147 |
|
public int getErrorCode() |
148 |
|
{ |
149 |
|
return vendorCode; |
150 |
|
} |
151 |
|
|
152 |
|
/** |
153 |
|
* Get any exception that is chained to this object. |
154 |
|
* |
155 |
|
* @return the exception chained to this object, or null |
156 |
|
*/ |
157 |
|
public SQLException getNextException() |
158 |
|
{ |
159 |
|
return next; |
160 |
|
} |
161 |
|
|
162 |
|
/** |
163 |
|
* Add a new exception to the end of the chain of exceptions that are |
164 |
|
* chained to this object. |
165 |
|
* |
166 |
|
* @param e the exception to add to the end of the chain |
167 |
|
*/ |
168 |
|
public void setNextException(SQLException e) |
169 |
|
{ |
170 |
|
if (e == null) |
171 |
|
return; |
172 |
|
SQLException entry = this; |
173 |
|
while (entry.next != null) |
174 |
|
entry = entry.next; |
175 |
|
entry.next = e; |
176 |
|
} |
177 |
} // class SQLException |
} // class SQLException |
|
|
|