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