KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mysql > jdbc > SQLError


1 /*
2    Copyright (C) 2002 MySQL AB
3
4       This program is free software; you can redistribute it and/or modify
5       it under the terms of the GNU General Public License as published by
6       the Free Software Foundation; either version 2 of the License, or
7       (at your option) any later version.
8
9       This program is distributed in the hope that it will be useful,
10       but WITHOUT ANY WARRANTY; without even the implied warranty of
11       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12       GNU General Public License for more details.
13
14       You should have received a copy of the GNU General Public License
15       along with this program; if not, write to the Free Software
16       Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18  */

19 package com.mysql.jdbc;
20
21 import java.util.Hashtable JavaDoc;
22
23
24 /**
25  * SQLError is a utility class that maps MySQL error codes to X/Open error
26  * codes as is required by the JDBC spec.
27  *
28  * @author Mark Matthews
29  * @version $Id: SQLError.java,v 1.6.2.4 2004/01/13 16:55:43 mmatthew Exp $
30  */

31 public class SQLError {
32     
33     public static final String JavaDoc SQL_STATE_TIMEOUT_EXPIRED = "S1T00";
34
35     public static final String JavaDoc SQL_STATE_DRIVER_NOT_CAPABLE = "S1C00";
36
37     public static final String JavaDoc SQL_STATE_ILLEGAL_ARGUMENT = "S1009";
38
39     public static final String JavaDoc SQL_STATE_INVALID_COLUMN_NUMBER = "S1002";
40
41     public static final String JavaDoc SQL_STATE_MEMORY_ALLOCATION_FAILURE = "S1001";
42
43     public static final String JavaDoc SQL_STATE_GENERAL_ERROR = "S1000";
44
45     public static final String JavaDoc SQL_STATE_NO_DEFAULT_FOR_COLUMN = "S0023";
46
47     public static final String JavaDoc SQL_STATE_COLUMN_NOT_FOUND = "S0022";
48
49     public static final String JavaDoc SQL_STATE_COLUMN_ALREADY_EXISTS = "S0021";
50
51     public static final String JavaDoc SQL_STATE_INDEX_NOT_FOUND = "S0012";
52
53     public static final String JavaDoc SQL_STATE_INDEX_ALREADY_EXISTS = "S0011";
54
55     public static final String JavaDoc SQL_STATE_BASE_TABLE_NOT_FOUND = "S0002";
56
57     public static final String JavaDoc SQL_STATE_BASE_TABLE_OR_VIEW_ALREADY_EXISTS = "S0001";
58
59     public static final String JavaDoc SQL_STATE_BASE_TABLE_OR_VIEW_NOT_FOUND = "42S02";
60
61     public static final String JavaDoc SQL_STATE_SYNTAX_ERROR = "42000";
62
63     public static final String JavaDoc SQL_STATE_DATETIME_FIELD_OVERFLOW = "22008";
64
65     public static final String JavaDoc SQL_STATE_NUMERIC_VALUE_OUT_OF_RANGE = "22003";
66
67     public static final String JavaDoc SQL_STATE_INSERT_VALUE_LIST_NO_MATCH_COL_LIST = "21S01";
68
69     public static final String JavaDoc SQL_STATE_DIVISION_BY_ZERO = "22012";
70
71     public static final String JavaDoc SQL_STATE_INVALID_AUTH_SPEC = "28000";
72
73     public static final String JavaDoc SQL_STATE_DEADLOCK = "41000";
74
75     public static final String JavaDoc SQL_STATE_CONNECTION_FAIL_DURING_TX = "08007";
76
77     public static final String JavaDoc SQL_STATE_CONNECTION_REJECTED = "08004";
78
79     public static final String JavaDoc SQL_STATE_UNABLE_TO_CONNECT_TO_DATASOURCE = "08001";
80
81     public static final String JavaDoc SQL_STATE_CONNECTION_IN_USE = "08002";
82
83     public static final String JavaDoc SQL_STATE_CONNECTION_NOT_OPEN = "08003";
84
85     public static final String JavaDoc SQL_STATE_WRONG_NO_OF_PARAMETERS = "07001";
86
87     public static final String JavaDoc SQL_STATE_MORE_THAN_ONE_ROW_UPDATED_OR_DELETED = "01S04";
88
89     public static final String JavaDoc SQL_STATE_NO_ROWS_UPDATED_OR_DELETED = "01S03";
90
91     public static final String JavaDoc SQL_STATE_ERROR_IN_ROW = "01S01";
92
93     public static final String JavaDoc SQL_STATE_COMMUNICATION_LINK_FAILURE = "08S01";
94
95     public static final String JavaDoc SQL_STATE_INVALID_CONNECTION_ATTRIBUTE = "01S00";
96
97     public static final String JavaDoc SQL_STATE_PRIVILEGE_NOT_REVOKED = "01006";
98
99     public static final String JavaDoc SQL_STATE_DATE_TRUNCATED = "01004";
100
101     public static final String JavaDoc SQL_STATE_DISCONNECT_ERROR = "01002";
102     
103     private static Hashtable JavaDoc mysqlToSqlState;
104     private static Hashtable JavaDoc sqlStateMessages;
105
106     static {
107         sqlStateMessages = new Hashtable JavaDoc();
108         sqlStateMessages.put(SQL_STATE_DISCONNECT_ERROR, "Disconnect error");
109         sqlStateMessages.put(SQL_STATE_DATE_TRUNCATED, "Data truncated");
110         sqlStateMessages.put(SQL_STATE_PRIVILEGE_NOT_REVOKED,
111             "Privilege not revoked");
112         sqlStateMessages.put(SQL_STATE_INVALID_CONNECTION_ATTRIBUTE,
113             "Invalid connection string attribute");
114         sqlStateMessages.put(SQL_STATE_ERROR_IN_ROW, "Error in row");
115         sqlStateMessages.put(SQL_STATE_NO_ROWS_UPDATED_OR_DELETED,
116             "No rows updated or deleted");
117         sqlStateMessages.put(SQL_STATE_MORE_THAN_ONE_ROW_UPDATED_OR_DELETED,
118             "More than one row updated or deleted");
119         sqlStateMessages.put(SQL_STATE_WRONG_NO_OF_PARAMETERS,
120             "Wrong number of parameters");
121         sqlStateMessages.put(SQL_STATE_UNABLE_TO_CONNECT_TO_DATASOURCE,
122             "Unable to connect to data source");
123         sqlStateMessages.put(SQL_STATE_CONNECTION_IN_USE, "Connection in use");
124         sqlStateMessages.put(SQL_STATE_CONNECTION_NOT_OPEN,
125             "Connection not open");
126         sqlStateMessages.put(SQL_STATE_CONNECTION_REJECTED,
127             "Data source rejected establishment of connection");
128         sqlStateMessages.put(SQL_STATE_CONNECTION_FAIL_DURING_TX,
129             "Connection failure during transaction");
130         sqlStateMessages.put(SQL_STATE_COMMUNICATION_LINK_FAILURE,
131             "Communication link failure");
132         sqlStateMessages.put(SQL_STATE_INSERT_VALUE_LIST_NO_MATCH_COL_LIST,
133             "Insert value list does not match column list");
134         sqlStateMessages.put(SQL_STATE_NUMERIC_VALUE_OUT_OF_RANGE,
135             "Numeric value out of range");
136         sqlStateMessages.put(SQL_STATE_DATETIME_FIELD_OVERFLOW,
137             "Datetime field overflow");
138         sqlStateMessages.put(SQL_STATE_DIVISION_BY_ZERO, "Division by zero");
139         sqlStateMessages.put(SQL_STATE_DEADLOCK,
140             "Deadlock found when trying to get lock; Try restarting transaction");
141         sqlStateMessages.put(SQL_STATE_INVALID_AUTH_SPEC,
142             "Invalid authorization specification");
143         sqlStateMessages.put(SQL_STATE_SYNTAX_ERROR,
144             "Syntax error or access violation");
145         sqlStateMessages.put(SQL_STATE_BASE_TABLE_OR_VIEW_NOT_FOUND,
146             "Base table or view not found");
147         sqlStateMessages.put(SQL_STATE_BASE_TABLE_OR_VIEW_ALREADY_EXISTS,
148             "Base table or view already exists");
149         sqlStateMessages.put(SQL_STATE_BASE_TABLE_NOT_FOUND,
150             "Base table not found");
151         sqlStateMessages.put(SQL_STATE_INDEX_ALREADY_EXISTS,
152             "Index already exists");
153         sqlStateMessages.put(SQL_STATE_INDEX_NOT_FOUND, "Index not found");
154         sqlStateMessages.put(SQL_STATE_COLUMN_ALREADY_EXISTS,
155             "Column already exists");
156         sqlStateMessages.put(SQL_STATE_COLUMN_NOT_FOUND, "Column not found");
157         sqlStateMessages.put(SQL_STATE_NO_DEFAULT_FOR_COLUMN,
158             "No default for column");
159         sqlStateMessages.put(SQL_STATE_GENERAL_ERROR, "General error");
160         sqlStateMessages.put(SQL_STATE_MEMORY_ALLOCATION_FAILURE,
161             "Memory allocation failure");
162         sqlStateMessages.put(SQL_STATE_INVALID_COLUMN_NUMBER,
163             "Invalid column number");
164         sqlStateMessages.put(SQL_STATE_ILLEGAL_ARGUMENT,
165             "Invalid argument value");
166         sqlStateMessages.put(SQL_STATE_DRIVER_NOT_CAPABLE, "Driver not capable");
167         sqlStateMessages.put(SQL_STATE_TIMEOUT_EXPIRED, "Timeout expired");
168
169         //
170
// Map MySQL error codes to X/Open error codes
171
//
172
mysqlToSqlState = new Hashtable JavaDoc();
173
174         //
175
// Communications Errors
176
//
177
// ER_CON_COUNT_ERROR 1040
178
// ER_BAD_HOST_ERROR 1042
179
// ER_HANDSHAKE_ERROR 1043
180
// ER_UNKNOWN_COM_ERROR 1047
181
// ER_IPSOCK_ERROR 1081
182
//
183
mysqlToSqlState.put(new Integer JavaDoc(1040), SQL_STATE_CONNECTION_REJECTED);
184         mysqlToSqlState.put(new Integer JavaDoc(1042), SQL_STATE_CONNECTION_REJECTED);
185         mysqlToSqlState.put(new Integer JavaDoc(1043), SQL_STATE_CONNECTION_REJECTED);
186         mysqlToSqlState.put(new Integer JavaDoc(1047),
187             SQL_STATE_COMMUNICATION_LINK_FAILURE);
188         mysqlToSqlState.put(new Integer JavaDoc(1081),
189             SQL_STATE_COMMUNICATION_LINK_FAILURE);
190
191         // ER_HOST_IS_BLOCKED 1129
192
// ER_HOST_NOT_PRIVILEGED 1130
193
mysqlToSqlState.put(new Integer JavaDoc(1129), SQL_STATE_CONNECTION_REJECTED);
194         mysqlToSqlState.put(new Integer JavaDoc(1130), SQL_STATE_CONNECTION_REJECTED);
195
196         //
197
// Authentication Errors
198
//
199
// ER_ACCESS_DENIED_ERROR 1045
200
//
201
mysqlToSqlState.put(new Integer JavaDoc(1045), SQL_STATE_INVALID_AUTH_SPEC);
202
203         //
204
// Resource errors
205
//
206
// ER_CANT_CREATE_FILE 1004
207
// ER_CANT_CREATE_TABLE 1005
208
// ER_CANT_LOCK 1015
209
// ER_DISK_FULL 1021
210
// ER_OUT_OF_RESOURCES 1041
211
//
212
// Out-of-memory errors
213
//
214
// ER_OUTOFMEMORY 1037
215
// ER_OUT_OF_SORTMEMORY 1038
216
//
217
mysqlToSqlState.put(new Integer JavaDoc(1037),
218             SQL_STATE_MEMORY_ALLOCATION_FAILURE);
219         mysqlToSqlState.put(new Integer JavaDoc(1038),
220             SQL_STATE_MEMORY_ALLOCATION_FAILURE);
221
222         //
223
// Syntax Errors
224
//
225
// ER_PARSE_ERROR 1064
226
// ER_EMPTY_QUERY 1065
227
//
228
mysqlToSqlState.put(new Integer JavaDoc(1064), SQL_STATE_SYNTAX_ERROR);
229         mysqlToSqlState.put(new Integer JavaDoc(1065), SQL_STATE_SYNTAX_ERROR);
230
231         //
232
// Invalid argument errors
233
//
234
// ER_WRONG_FIELD_WITH_GROUP 1055
235
// ER_WRONG_GROUP_FIELD 1056
236
// ER_WRONG_SUM_SELECT 1057
237
// ER_TOO_LONG_IDENT 1059
238
// ER_DUP_FIELDNAME 1060
239
// ER_DUP_KEYNAME 1061
240
// ER_DUP_ENTRY 1062
241
// ER_WRONG_FIELD_SPEC 1063
242
// ER_NONUNIQ_TABLE 1066
243
// ER_INVALID_DEFAULT 1067
244
// ER_MULTIPLE_PRI_KEY 1068
245
// ER_TOO_MANY_KEYS 1069
246
// ER_TOO_MANY_KEY_PARTS 1070
247
// ER_TOO_LONG_KEY 1071
248
// ER_KEY_COLUMN_DOES_NOT_EXIST 1072
249
// ER_BLOB_USED_AS_KEY 1073
250
// ER_TOO_BIG_FIELDLENGTH 1074
251
// ER_WRONG_AUTO_KEY 1075
252
// ER_NO_SUCH_INDEX 1082
253
// ER_WRONG_FIELD_TERMINATORS 1083
254
// ER_BLOBS_AND_NO_TERMINATED 1084
255
//
256
mysqlToSqlState.put(new Integer JavaDoc(1055), SQL_STATE_ILLEGAL_ARGUMENT);
257         mysqlToSqlState.put(new Integer JavaDoc(1056), SQL_STATE_ILLEGAL_ARGUMENT);
258         mysqlToSqlState.put(new Integer JavaDoc(1057), SQL_STATE_ILLEGAL_ARGUMENT);
259         mysqlToSqlState.put(new Integer JavaDoc(1059), SQL_STATE_ILLEGAL_ARGUMENT);
260         mysqlToSqlState.put(new Integer JavaDoc(1060), SQL_STATE_ILLEGAL_ARGUMENT);
261         mysqlToSqlState.put(new Integer JavaDoc(1061), SQL_STATE_ILLEGAL_ARGUMENT);
262         mysqlToSqlState.put(new Integer JavaDoc(1062), SQL_STATE_ILLEGAL_ARGUMENT);
263         mysqlToSqlState.put(new Integer JavaDoc(1063), SQL_STATE_ILLEGAL_ARGUMENT);
264         mysqlToSqlState.put(new Integer JavaDoc(1066), SQL_STATE_ILLEGAL_ARGUMENT);
265         mysqlToSqlState.put(new Integer JavaDoc(1067), SQL_STATE_ILLEGAL_ARGUMENT);
266         mysqlToSqlState.put(new Integer JavaDoc(1068), SQL_STATE_ILLEGAL_ARGUMENT);
267         mysqlToSqlState.put(new Integer JavaDoc(1069), SQL_STATE_ILLEGAL_ARGUMENT);
268         mysqlToSqlState.put(new Integer JavaDoc(1070), SQL_STATE_ILLEGAL_ARGUMENT);
269         mysqlToSqlState.put(new Integer JavaDoc(1071), SQL_STATE_ILLEGAL_ARGUMENT);
270         mysqlToSqlState.put(new Integer JavaDoc(1072), SQL_STATE_ILLEGAL_ARGUMENT);
271         mysqlToSqlState.put(new Integer JavaDoc(1073), SQL_STATE_ILLEGAL_ARGUMENT);
272         mysqlToSqlState.put(new Integer JavaDoc(1074), SQL_STATE_ILLEGAL_ARGUMENT);
273         mysqlToSqlState.put(new Integer JavaDoc(1075), SQL_STATE_ILLEGAL_ARGUMENT);
274         mysqlToSqlState.put(new Integer JavaDoc(1082), SQL_STATE_ILLEGAL_ARGUMENT);
275         mysqlToSqlState.put(new Integer JavaDoc(1083), SQL_STATE_ILLEGAL_ARGUMENT);
276         mysqlToSqlState.put(new Integer JavaDoc(1084), SQL_STATE_ILLEGAL_ARGUMENT);
277
278         //
279
// ER_WRONG_VALUE_COUNT 1058
280
//
281
mysqlToSqlState.put(new Integer JavaDoc(1058),
282             SQL_STATE_INSERT_VALUE_LIST_NO_MATCH_COL_LIST);
283
284         // ER_CANT_CREATE_DB 1006
285
// ER_DB_CREATE_EXISTS 1007
286
// ER_DB_DROP_EXISTS 1008
287
// ER_DB_DROP_DELETE 1009
288
// ER_DB_DROP_RMDIR 1010
289
// ER_CANT_DELETE_FILE 1011
290
// ER_CANT_FIND_SYSTEM_REC 1012
291
// ER_CANT_GET_STAT 1013
292
// ER_CANT_GET_WD 1014
293
// ER_UNEXPECTED_EOF 1039
294
// ER_CANT_OPEN_FILE 1016
295
// ER_FILE_NOT_FOUND 1017
296
// ER_CANT_READ_DIR 1018
297
// ER_CANT_SET_WD 1019
298
// ER_CHECKREAD 1020
299
// ER_DUP_KEY 1022
300
// ER_ERROR_ON_CLOSE 1023
301
// ER_ERROR_ON_READ 1024
302
// ER_ERROR_ON_RENAME 1025
303
// ER_ERROR_ON_WRITE 1026
304
// ER_FILE_USED 1027
305
// ER_FILSORT_ABORT 1028
306
// ER_FORM_NOT_FOUND 1029
307
// ER_GET_ERRNO 1030
308
// ER_ILLEGAL_HA 1031
309
// ER_KEY_NOT_FOUND 1032
310
// ER_NOT_FORM_FILE 1033
311
// ER_DBACCESS_DENIED_ERROR 1044
312
// ER_NO_DB_ERROR 1046
313
// ER_BAD_NULL_ERROR 1048
314
// ER_BAD_DB_ERROR 1049
315
// ER_TABLE_EXISTS_ERROR 1050
316
// ER_BAD_TABLE_ERROR 1051
317
mysqlToSqlState.put(new Integer JavaDoc(1051),
318             SQL_STATE_BASE_TABLE_OR_VIEW_NOT_FOUND);
319
320         // ER_NON_UNIQ_ERROR 1052
321
// ER_BAD_FIELD_ERROR 1054
322
mysqlToSqlState.put(new Integer JavaDoc(1054), SQL_STATE_COLUMN_NOT_FOUND);
323
324         // ER_TEXTFILE_NOT_READABLE 1085
325
// ER_FILE_EXISTS_ERROR 1086
326
// ER_LOAD_INFO 1087
327
// ER_ALTER_INFO 1088
328
// ER_WRONG_SUB_KEY 1089
329
// ER_CANT_REMOVE_ALL_FIELDS 1090
330
// ER_CANT_DROP_FIELD_OR_KEY 1091
331
// ER_INSERT_INFO 1092
332
// ER_INSERT_TABLE_USED 1093
333
// ER_LOCK_DEADLOCK 1213
334
mysqlToSqlState.put(new Integer JavaDoc(1205), SQL_STATE_DEADLOCK);
335         mysqlToSqlState.put(new Integer JavaDoc(1213), SQL_STATE_DEADLOCK);
336     }
337
338     static String JavaDoc get(String JavaDoc stateCode) {
339         return (String JavaDoc) sqlStateMessages.get(stateCode);
340     }
341
342     /**
343      * Map MySQL error codes to X/Open error codes
344      *
345      * @param errno the MySQL error code
346      *
347      * @return the corresponding X/Open error code
348      */

349     static String JavaDoc mysqlToXOpen(int errno) {
350         Integer JavaDoc err = new Integer JavaDoc(errno);
351
352         if (mysqlToSqlState.containsKey(err)) {
353             return (String JavaDoc) mysqlToSqlState.get(err);
354         } else {
355             return SQL_STATE_GENERAL_ERROR;
356         }
357     }
358 }
359
Popular Tags