1 19 package com.mysql.jdbc; 20 21 import java.util.Hashtable ; 22 23 24 31 public class SQLError { 32 33 public static final String SQL_STATE_TIMEOUT_EXPIRED = "S1T00"; 34 35 public static final String SQL_STATE_DRIVER_NOT_CAPABLE = "S1C00"; 36 37 public static final String SQL_STATE_ILLEGAL_ARGUMENT = "S1009"; 38 39 public static final String SQL_STATE_INVALID_COLUMN_NUMBER = "S1002"; 40 41 public static final String SQL_STATE_MEMORY_ALLOCATION_FAILURE = "S1001"; 42 43 public static final String SQL_STATE_GENERAL_ERROR = "S1000"; 44 45 public static final String SQL_STATE_NO_DEFAULT_FOR_COLUMN = "S0023"; 46 47 public static final String SQL_STATE_COLUMN_NOT_FOUND = "S0022"; 48 49 public static final String SQL_STATE_COLUMN_ALREADY_EXISTS = "S0021"; 50 51 public static final String SQL_STATE_INDEX_NOT_FOUND = "S0012"; 52 53 public static final String SQL_STATE_INDEX_ALREADY_EXISTS = "S0011"; 54 55 public static final String SQL_STATE_BASE_TABLE_NOT_FOUND = "S0002"; 56 57 public static final String SQL_STATE_BASE_TABLE_OR_VIEW_ALREADY_EXISTS = "S0001"; 58 59 public static final String SQL_STATE_BASE_TABLE_OR_VIEW_NOT_FOUND = "42S02"; 60 61 public static final String SQL_STATE_SYNTAX_ERROR = "42000"; 62 63 public static final String SQL_STATE_DATETIME_FIELD_OVERFLOW = "22008"; 64 65 public static final String SQL_STATE_NUMERIC_VALUE_OUT_OF_RANGE = "22003"; 66 67 public static final String SQL_STATE_INSERT_VALUE_LIST_NO_MATCH_COL_LIST = "21S01"; 68 69 public static final String SQL_STATE_DIVISION_BY_ZERO = "22012"; 70 71 public static final String SQL_STATE_INVALID_AUTH_SPEC = "28000"; 72 73 public static final String SQL_STATE_DEADLOCK = "41000"; 74 75 public static final String SQL_STATE_CONNECTION_FAIL_DURING_TX = "08007"; 76 77 public static final String SQL_STATE_CONNECTION_REJECTED = "08004"; 78 79 public static final String SQL_STATE_UNABLE_TO_CONNECT_TO_DATASOURCE = "08001"; 80 81 public static final String SQL_STATE_CONNECTION_IN_USE = "08002"; 82 83 public static final String SQL_STATE_CONNECTION_NOT_OPEN = "08003"; 84 85 public static final String SQL_STATE_WRONG_NO_OF_PARAMETERS = "07001"; 86 87 public static final String SQL_STATE_MORE_THAN_ONE_ROW_UPDATED_OR_DELETED = "01S04"; 88 89 public static final String SQL_STATE_NO_ROWS_UPDATED_OR_DELETED = "01S03"; 90 91 public static final String SQL_STATE_ERROR_IN_ROW = "01S01"; 92 93 public static final String SQL_STATE_COMMUNICATION_LINK_FAILURE = "08S01"; 94 95 public static final String SQL_STATE_INVALID_CONNECTION_ATTRIBUTE = "01S00"; 96 97 public static final String SQL_STATE_PRIVILEGE_NOT_REVOKED = "01006"; 98 99 public static final String SQL_STATE_DATE_TRUNCATED = "01004"; 100 101 public static final String SQL_STATE_DISCONNECT_ERROR = "01002"; 102 103 private static Hashtable mysqlToSqlState; 104 private static Hashtable sqlStateMessages; 105 106 static { 107 sqlStateMessages = new Hashtable (); 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 mysqlToSqlState = new Hashtable (); 173 174 mysqlToSqlState.put(new Integer (1040), SQL_STATE_CONNECTION_REJECTED); 184 mysqlToSqlState.put(new Integer (1042), SQL_STATE_CONNECTION_REJECTED); 185 mysqlToSqlState.put(new Integer (1043), SQL_STATE_CONNECTION_REJECTED); 186 mysqlToSqlState.put(new Integer (1047), 187 SQL_STATE_COMMUNICATION_LINK_FAILURE); 188 mysqlToSqlState.put(new Integer (1081), 189 SQL_STATE_COMMUNICATION_LINK_FAILURE); 190 191 mysqlToSqlState.put(new Integer (1129), SQL_STATE_CONNECTION_REJECTED); 194 mysqlToSqlState.put(new Integer (1130), SQL_STATE_CONNECTION_REJECTED); 195 196 mysqlToSqlState.put(new Integer (1045), SQL_STATE_INVALID_AUTH_SPEC); 202 203 mysqlToSqlState.put(new Integer (1037), 218 SQL_STATE_MEMORY_ALLOCATION_FAILURE); 219 mysqlToSqlState.put(new Integer (1038), 220 SQL_STATE_MEMORY_ALLOCATION_FAILURE); 221 222 mysqlToSqlState.put(new Integer (1064), SQL_STATE_SYNTAX_ERROR); 229 mysqlToSqlState.put(new Integer (1065), SQL_STATE_SYNTAX_ERROR); 230 231 mysqlToSqlState.put(new Integer (1055), SQL_STATE_ILLEGAL_ARGUMENT); 257 mysqlToSqlState.put(new Integer (1056), SQL_STATE_ILLEGAL_ARGUMENT); 258 mysqlToSqlState.put(new Integer (1057), SQL_STATE_ILLEGAL_ARGUMENT); 259 mysqlToSqlState.put(new Integer (1059), SQL_STATE_ILLEGAL_ARGUMENT); 260 mysqlToSqlState.put(new Integer (1060), SQL_STATE_ILLEGAL_ARGUMENT); 261 mysqlToSqlState.put(new Integer (1061), SQL_STATE_ILLEGAL_ARGUMENT); 262 mysqlToSqlState.put(new Integer (1062), SQL_STATE_ILLEGAL_ARGUMENT); 263 mysqlToSqlState.put(new Integer (1063), SQL_STATE_ILLEGAL_ARGUMENT); 264 mysqlToSqlState.put(new Integer (1066), SQL_STATE_ILLEGAL_ARGUMENT); 265 mysqlToSqlState.put(new Integer (1067), SQL_STATE_ILLEGAL_ARGUMENT); 266 mysqlToSqlState.put(new Integer (1068), SQL_STATE_ILLEGAL_ARGUMENT); 267 mysqlToSqlState.put(new Integer (1069), SQL_STATE_ILLEGAL_ARGUMENT); 268 mysqlToSqlState.put(new Integer (1070), SQL_STATE_ILLEGAL_ARGUMENT); 269 mysqlToSqlState.put(new Integer (1071), SQL_STATE_ILLEGAL_ARGUMENT); 270 mysqlToSqlState.put(new Integer (1072), SQL_STATE_ILLEGAL_ARGUMENT); 271 mysqlToSqlState.put(new Integer (1073), SQL_STATE_ILLEGAL_ARGUMENT); 272 mysqlToSqlState.put(new Integer (1074), SQL_STATE_ILLEGAL_ARGUMENT); 273 mysqlToSqlState.put(new Integer (1075), SQL_STATE_ILLEGAL_ARGUMENT); 274 mysqlToSqlState.put(new Integer (1082), SQL_STATE_ILLEGAL_ARGUMENT); 275 mysqlToSqlState.put(new Integer (1083), SQL_STATE_ILLEGAL_ARGUMENT); 276 mysqlToSqlState.put(new Integer (1084), SQL_STATE_ILLEGAL_ARGUMENT); 277 278 mysqlToSqlState.put(new Integer (1058), 282 SQL_STATE_INSERT_VALUE_LIST_NO_MATCH_COL_LIST); 283 284 mysqlToSqlState.put(new Integer (1051), 318 SQL_STATE_BASE_TABLE_OR_VIEW_NOT_FOUND); 319 320 mysqlToSqlState.put(new Integer (1054), SQL_STATE_COLUMN_NOT_FOUND); 323 324 mysqlToSqlState.put(new Integer (1205), SQL_STATE_DEADLOCK); 335 mysqlToSqlState.put(new Integer (1213), SQL_STATE_DEADLOCK); 336 } 337 338 static String get(String stateCode) { 339 return (String ) sqlStateMessages.get(stateCode); 340 } 341 342 349 static String mysqlToXOpen(int errno) { 350 Integer err = new Integer (errno); 351 352 if (mysqlToSqlState.containsKey(err)) { 353 return (String ) mysqlToSqlState.get(err); 354 } else { 355 return SQL_STATE_GENERAL_ERROR; 356 } 357 } 358 } 359 | Popular Tags |