I went through the SQL:2008 draft standard and created an enum for all
SQLStates. The only SQLStates without full Javadoc are HZxxx for
remote database access (patches welcome!). This was *a lot* of work :)
I hope you find this useful.
Gili
-------------------------------
import com.google.common.collect.Maps;
import java.util.Map;
/**
* Standard SQLState codes.
*
* Codes are listed in the same order as the SQL:2008 standard.
*
* @author Gili Tzabari
* @see
http://en.wikipedia.org/wiki/SQL#cite_note-27
* @see
http://kb.askmonty.org/v/sqlstate-codes
*/
public enum SQLState
{
/**
* Returned if the statement contains a preparable dynamic cursor
name that is ambiguous.
*/
AMBIGUOUS_CURSOR_NAME("3C000"),
/**
* Attempted to assign a value to a non-updatable column.
*/
CANNOT_ASSIGN_TO_NON_UPDATABLE_COLUMN("0U000"),
/**
* Returned if any object column is directly or indirectly referenced
in the <code>order by</code> clause
* of a dynamic cursor definition.
*/
CANNOT_ASSIGN_TO_ORDERING_COLUMN("0V000"),
/**
* The result of a SELECT INTO, scalar fullselect, or subquery of a
basic predicate returned more
* than one value.
*/
CARDINALITY_VIOLATION("21000"),
/**
* Unable to establish a database connection.
*/
CONNECTION_EXCEPTION("08000"),
/**
* Attempted to disconnect a non-existent database connection.
*/
CONNECTION_DOES_NOT_EXIST("08003"),
/**
* The specified connection could not be selected.
*/
CONNECTION_FAILURE("08006"),
/**
* Returned if a connection with the specified name is already
established.
*/
CONNECTION_NAME_IN_USE("08002"),
/**
* Returned if the client is unable to connect to the database.
*/
CANNOT_ESTABLISH_CONNECTION("08001"),
/**
* Returned if the server rejected the client's connection request.
*/
CONNECTION_REJECTED("08004"),
/**
* Connection lost while committing or rolling back a transaction.
The client cannot verify
* whether the transaction was committed successfully, rolled back or
left active.
*/
TRANSACTION_RESOLUTION_UNKNOWN("08007"),
/**
* The "cursor sensitivity exception" class identifies exception
conditions that relate to Cursors
* and their sensitivity attribute.
*
* If a holdable cursor is open during an SQL-transaction <code>T</
code> and it is held open for
* a subsequent SQL-transaction, then whether any significant changes
made to SQL-data (by
* <code>T</code> or any subsequent SQL-transaction in which the
cursor is held open) are visible
* through that cursor in the subsequent SQL-transaction before that
cursor is closed is
* determined as follows:
*
* - If the cursor is insensitive, then significant changes are not
visible.
* - If the cursor is sensitive, then the visibility of significant
changes is implementation-defined.
* - If the cursor is asensitive, then the visibility of significant
changes.
*/
CURSOR_SENSITIVITY_EXCEPTION("36000"),
/**
* Returned if a sensitive cursor has not been held into a subsequent
SQL-transaction, and the
* change resulting from the successful execution of this statement
could not be made visible to
* the cursor.
*
* For example, an attempt was made to execute a positioned DELETE
statement, but there is a
* sensitive Cursor open, and (for some implementation-dependent
reason) the effects of the
* DELETE cannot be made visible via that Cursor.
*/
CURSOR_SENSITIVITY_REQUEST_FAILED("36002"),
/**
* A cursor is insensitive, and the SQL-implementation is unable to
guarantee that significant
* changes will be invisible through the cursor during the SQL-
transaction in which it is opened
* and every subsequent SQL-transaction during which it may be held
open.
*/
CURSOR_SENSITIVITY_REQUEST_REJECTED("36001"),
/**
* The specified data was inappropriate for the column type.
*/
DATA_EXCEPTION("22000"),
/**
* The maximum number of elements in the target array is less than
the number of elements in
* the source array and the extra source elements are not all NULL.
*/
ARRAY_DATA_RIGHT_TRUNCATION_EXCEPTION("2202F"),
/**
* Attempted to reference an array index which is out of range.
*/
ARRAY_ELEMENT_ERROR("2202E"),
/**
* Attempted to replace a substring that matches an XQuery regular
expression with a replacement
* character string, but the matching substring is a zero-length
string.
*/
ZERO_LENGTH_STRING("2201U"),
/**
* A character is not in the coded character set or the conversion is
not supported.
*/
CHARACTER_NOT_IN_REPERTOIRE("22021"),
/**
* Datetime field overflow occurred; for example, an arithmetic
operation on a date or timestamp
* has a result that is not within the valid range of dates. See also
SQLSTATE 22007.
*/
DATETIME_FIELD_OVERFLOW("22008"),
/**
* Attempted to divide a number by zero.
*/
DIVISION_BY_ZERO("22012"),
/**
* An error occurred on assignment.
*/
ERROR_IN_ASSIGNMENT("22005"),
/**
* Attempted to use an invalid escape character.
*/
ESCAPE_CHARACTER_CONFLICT("2200B"),
/**
* Indicator is too small for size value.
*/
INDICATOR_OVERFLOW("22022"),
/**
* The value of an interval field exceeded its maximum value. See
also SQLSTATE 22006.
*/
INTERVAL_FIELD_OVERFLOW("22015"),
/**
The result of an aggregate function is out of the range of an
interval type.
*/
INTERVAL_VALUE_OUT_OF_RANGE("2200P"),
/**
* Passed an invalid argument into a LOG function.
*/
INVALID_ARGUMENT_FOR_LOGARITHM("2201E"),
/**
* Passed an invalid argument into a POWER function.
*/
INVALID_ARGUMENT_FOR_POWER_FUNCTION("2201F"),
/**
* Passed an invalid argument into a WIDTH_BUCKET function.
*/
INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION("2201G"),
/**
* Tried to convert a value to a data type where the conversion is
undefined, or when an error
* occurred trying to convert.
*/
INVALID_CHARACTER_VALUE_FOR_CAST("22018"),
/**
* An invalid datetime format was detected; that is, an invalid
string representation or value
* was specified. See also SQLSTATE 22008, 22018.
*/
INVALID_DATETIME_FORMAT("22007"),
/**
* The LIKE predicate has an invalid escape character.
*/
INVALID_ESCAPE_CHARACTER("22019"),
/**
* Returned if the length of the escape octet is not one.
*/
INVALID_ESCAPE_OCTET("2200D"),
/**
* The LIKE predicate string pattern contains an invalid occurrence
of an escape character.
*/
INVALID_ESCAPE_SEQUENCE("22025"),
/**
* The value of the indicator variable is less than zero but is not
equal to -1 (SQL_NULL_DATA).
*/
INVALID_INDICATOR_PARAMETER_VALUE("22010"),
/**
* Specified an interval with an invalid format. For example, a year-
month interval should
* contain only a year integer, a '-' separator, and a month integer.
See also SQLSTATE 22015.
*/
INVALID_INTERVAL_FORMAT("22006"),
/**
* A parameter or host variable value is invalid.
*/
INVALID_PARAMETER_VALUE("22023"),
/**
* Returned if the window frame bound preceding or following a WINDOW
function is negative or null.
*
* @see
http://en.wikipedia.org/wiki/Select_%28SQL%29#Window_function
*/
INVALID_SIZE_IN_WINDOW_FUNCTION("22013"),
/**
* Returned if the specified regular expression does not have a valid
format.
*/
INVALID_REGULAR_EXPRESSION("2201B"),
/**
* Invalid repeat argument in SAMPLE clause.
*/
INVALID_REPEAT_ARGUMENT_IN_SAMPLE_CLAUSE("2202G"),
/**
* The sample size was less than 0 or more than 100.
*/
INVALID_SAMPLE_SIZE("2202H"),
/**
* The time zone displacement value is outside the range -12:59 to
14:00.
*
* This could happen for "SET LOCAL TIME ZONE INTERVAL '22:00' HOUR
TO MINUTE;", or for
* "TIMESTAMP '1994-01-01 02:00:00+10:00'". (In the latter case, it
is the result of the
* calculation that is a problem.)
*/
INVALID_TIME_ZONE_DISPLACEMENT_VALUE("22009"),
/**
* A required escape character was missing or in the wrong location.
*/
INVALID_USE_OF_ESCAPE_CHARACTER("2200C"),
/**
* The specified xquery option flag is invalid.
*/
INVALID_XQUERY_OPTION_FLAG("2201T"),
/**
* The regular expression specified in the xquery expression is
invalid.
*/
INVALID_XQUERY_REGULAR_EXPRESSION("2201S"),
/**
* The replacement string specified in the xquery expression is
invalid.
*/
INVALID_XQUERY_REPLACEMENT_STRING("2201V"),
/**
* Returned if the return value of a type-preserving function is not
compatible with most specific
* return type of the function.
*/
MOST_SPECIFIC_TYPE_MISMATCH("2200G"),
/**
* The result of an aggregate function is out of the range of a
multiset type.
*/
MULTISET_VALUE_OVERFLOW("2200Q"),
/**
* Returned when an operation inserts a non-character code point into
a unicode string.
*/
NONCHARACTER_IN_UCS_STRING("22029"),
/**
* Attempted to invoke a mutator function on NULL.
*/
NULL_INSTANCE_USED_IN_MUTATOR_FUNCTION("2202D"),
/**
* Attempted to insert a null row into a table that disallows them.
*/
NULL_ROW_NOT_PERMITTED_IN_TABLE("2201C"),
/**
* Attempted to assign a value to an array index whose value was
null.
*/
NULL_VALUE_IN_ARRAY_TARGET("2200E"),
/**
* A null value, or the absence of an indicator parameter was
detected; for example, the null
* value cannot be assigned to a host variable, because no indicator
variable is specified.
*/
NULL_VALUE_NO_INDICATOR_PARAMETER("22002"),
/**
* A null value is not allowed.
*/
NULL_VALUE_NOT_ALLOWED_BY_FUNCTION("22004"),
/**
* A numeric value is out of range. Often this is the result of an
arithmetic overflow.
* For example, "UPDATE ... SET SMALLINT_COLUMN = 9999999999".
*/
NUMERIC_VALUE_OUT_OF_RANGE("22003"),
/**
* Returned if a sequence generator cannot generate any more numbers
because it has already
* generated its maximum value and it is configured with NO CYCLE.
*/
SEQUENCE_GENERATOR_LIMIT_EXCEEDED("2200H"),
/**
* Attempted to update a bit string but the specified value does not
match the length of the bit
* string.
*/
STRING_DATA_LENGTH_MISMATCH("22026"),
/**
* Character data, right truncation occurred; for example, an update
or insert value is a string
* that is too long for the column, or a datetime value cannot be
assigned to a host variable,
* because it is too small. No truncation actually occurs since the
SQL statement fails. See
* SQLSTATE 01004.
*/
STRING_DATA_RIGHT_TRUNCATION("22001"),
/**
* A substring error occurred; for example, an argument of SUBSTR is
out of range.
*/
SUBSTRING_ERROR("22011"),
/**
* Attempted to invoke the TRIM function with a first argument whose
length was greater than
* one character.
*/
TRIM_ERROR("22027"),
/**
* A NULL-terminated input host variable or parameter did not contain
a NULL.
*/
UNTERMINATED_C_STRING("22024"),
/**
* Character strings must have a length of one.
*/
ZERO_LENGTH_CHARACTER_STRING("2200F"),
/**
* Attempted to "REVOKE GRANT OPTION FOR" with dependent privileges
and without a "CASCADE".
*/
DEPENDENT_PRIVILEGE_DESCRIPTORS_STILL_EXIST("2B000"),
/**
* An error occurred while invoking a diagnostics function.
*/
DIAGNOSTICS_EXCEPTION("0Z000"),
/**
* Attempted to PUSH an operation onto the diagnostics stack but the
number of operations in
* the stack exceed the implementation-dependent maximum.
*/
MAXIMUM_NUMBER_OF_STACKED_DIAGNOSTICS_AREAS_EXCEEDED("0Z001"),
/**
* An error occurred while executing dynamic SQL.
*/
DYNAMIC_SQL_ERROR("07000"),
/**
* Returned if prepared statement does not conform to the Format and
Syntax Rules of a dynamic
* single row select statement.
*/
CURSOR_SPECIFICATION_CANNOT_BE_EXECUTED("07003"),
/**
* The supplied input or output arguments could not be transformed to
the types expected by the
* dynamic SQL script.
*/
DATA_TYPE_TRANSFORM_FUNCTION_VIOLATION("0700B"),
/**
* Specified a descriptor item name DATA on a descriptor area whose
type is ARRAY, ARRAY LOCATOR,
* MULTISET, or MULTISET LOCATOR.
*/
INVALID_DATA_TARGET("0700D"),
/**
* Specified an invalid datetime interval.
*/
INVALID_DATETIME_INTERVAL_CODE("0700F"),
/**
* Using the embedded SQL ALLOCATE DESCRIPTOR statement, you
allocated a 5-item descriptor.
* Now you are trying to use the sixth item in that descriptor. See
also SQLSTATE 07009.
*/
INVALID_DESCRIPTOR_COUNT("07008"),
/**
* you are using a CLI descriptor function (such as SQLBindCol or
SQLBindParameter) and the
* Column number is less than 1 or greater than the maximum number of
Columns. Or, you are using
* the embedded SQL ALLOCATE DESCRIPTOR statement with a size which
is less than 1 or greater
* than an implementation-defined maximum. See also SQLSTATE 07008.
*/
INVALID_DESCRIPTOR_INDEX("07009"),
/**
* Invalid LEVEL specified in SET DESCRIPTOR statement.
*/
INVALID_LEVEL_VALUE("0700E"),
/**
* The statement name of the cursor identifies a prepared statement
that cannot be associated
* with a cursor.
*/
PREPARED_STATEMENT_NOT_A_CURSOR_SPECIFICATION("07005"),
/**
* An input variable, transition variable, or parameter marker cannot
be used, because of its
* data type.
*/
RESTRICTED_DATA_TYPE_ATTRIBUTE_VIOLATION("07006"),
/**
* Attempted to GET DESCRIPTOR DATA on a descriptor area whose type
is ARRAY, ARRAY LOCATOR,
* MULTISET, or MULTISET LOCATOR.
*/
UNDEFINED_DATA_VALUE("0700C"),
/**
* You might encounter this error if you set the length of a
descriptor, then
* <code>EXECUTE ... USING descriptor</code>. Often this exception
results from consistency-check
* failure during SQLExecute.
*/
USING_CLAUSE_DOES_NOT_MATCH_DYNAMIC_PARAMETERS("07001"),
/**
* Often this exception results from consistency-check failure during
SQLExecute.
*
* Sometimes this exception results from an incorrect number of
parameters. See also
* SQLSTATE 07008.
*/
USING_CLAUSE_DOES_NOT_MATCH_TARGET_SPECIFICATIONS("07002"),
/**
* You cannot simply EXECUTE an SQL statement which has dynamic
parameters — you also need to
* use a USING clause. See also SQLSTATE 07007.
*/
USING_CLAUSE_REQUIRED_FOR_DYNAMIC_PARAMETERS("07004"),
/**
* You cannot simply EXECUTE an SQL statement which has result fields
— you also need to use a
* USING clause. See also SQLSTATE 07004.
*/
USING_CLAUSE_REQUIRED_FOR_RESULT_FIELDS("07007"),
/**
* An error occurred executing an external routine.
*
* External routines are stored procedures implemented by non-SQL
languages (i.e. Java).
*/
EXTERNAL_ROUTINE_EXCEPTION("38000"),
/**
* The external routine is not allowed to execute SQL statements.
*/
CONTAINING_SQL_NOT_PERMITTED("38001"),
/**
* The routine attempted to modify data, but the routine was not
defined as MODIFIES SQL DATA.
*/
MODIFYING_SQL_DATA_NOT_PERMITTED("38002"),
/**
* The statement is not allowed in a routine.
*/
PROHIBITED_SQL_STATEMENT_ATTEMPTED_BY_ROUTINE("38003"),
/**
* The external routine attempted to read data, but the routine was
not defined as READS SQL DATA.
*/
READING_SQL_DATA_NOT_PERMITTED_BY_ROUTINE("38004"),
/**
* An error occurred before or after invoking an external routine.
*
* External routines are stored procedures implemented by non-SQL
languages (i.e. Java).
*/
EXTERNAL_ROUTINE_INVOCATION_EXCEPTION("39000"),
/**
* A null value is not allowed for an IN or INOUT argument when using
PARAMETER STYLE GENERAL or
* an argument that is a Java™ primitive type.
*/
NULL_VALUE_NOT_ALLOWED_BY_EXTERNAL_ROUTINE("39004"),
/**
* The "feature not supported" class identifies exception conditions
that relate to features
* you're trying to use, but that your DBMS hasn't implemented. The
Standard does not specify
* what will cause this SQLSTATE, possibly because the expectation is
that all features will
* be supported.
*/
FEATURE_NOT_SUPPORTED("0A000"),
/**
* A single transaction cannot be performed on multiple servers. Such
a feature is sophisticated
* and rare.
*/
MULTIPLE_SERVER_TRANSACTIONS("0A001"),
/**
* The operation violated a table constraint.
*/
INTEGRITY_CONSTRAINT_VIOLATION("23000"),
/**
* The update or delete of a parent key is prevented by a RESTRICT
update or delete rule.
* See also SQLSTATE 40002.
*/
RESTRICT_VIOLATION("23001"),
/**
* Authorization name is invalid.
*/
INVALID_AUTHORIZATION_SPECIFICATION("28000"),
/**
* A <code>Catalog name</code> could be invalid if it is used as a
qualifier or as the
* argument of SET CATALOG, and does not refer to an existing Catalog
or is not a valid
* <code>identifier</code>.
*/
INVALID_CATALOG_NAME("3D000"),
/**
* Presumably an invalid Character set name would be one that begins
with a digit, contains a
* non-Latin letter, etc.
*/
INVALID_CHARACTER_SET_NAME("2C000"),
/**
* With embedded SQL, you get this by saying "GET DIAGNOSTICS
EXCEPTION 0". With the CLI, you get
* this by calling SQLGetDiagRec or SQLGetDiagField with a
RecordNumber parameter less than 1.
* If RecordNumber is greater than the number of status records, you
don't get this error.
* Instead, you get an NO_DATA return code.
*/
INVALID_CONDITION_NUMBER("35000"),
/**
* For a CONNECT statement, the argument must be a valid
<code>identifier</code>.
*/
INVALID_CONNECTION_NAME("2E000"),
/**
* Cursor name is invalid.
*/
INVALID_CURSOR_NAME("34000"),
/**
* The cursor is closed or has no current row.
*/
INVALID_CURSOR_STATE("24000"),
/**
* The specified grantor may not GRANT access.
*/
INVALID_GRANTOR("0L000"),
/**
* Invalid role specification. The specified role does not exist or
is not granted to the
* specified user.
*/
INVALID_ROLE_SPECIFICATION("0P000"),
/**
* The schema (collection) name is invalid.
*/
INVALID_SCHEMA_NAME("3F000"),
/**
* An error occurred while specifying Schema paths.
*/
INVALID_SCHEMA_NAME_LIST_SPECIFICATION("0E000"),
/**
* A <code>Collation name</code> could be invalid if it is used as a
qualifier or as the
* argument of SET COLLATION, and does not refer to an existing
Collation or is not a valid
* <code>identifier</code>.
*/
INVALID_COLLATION_NAME("2H000"),
/**
* Returned if, in embedded SQL, you use "EXECUTE ... USING
DESCRIPTOR 'X';", a descriptor named
* X must exist.
*/
INVALID_SQL_DESCRIPTOR_NAME("33000"),
/**
* Returned if the SQL-session context of the current SQL-session
does not include a result set
* sequence brought into existence by an invocation of SQL-invoked
procedure by the active
* SQL-invoked routine.
*/
INVALID_SQL_INVOKED_PROCEDURE_REFERENCE("0M000"),
/**
* Probable cause: you failed to PREPARE an SQL statement and now you
are trying to EXECUTE it.
*/
INVALID_SQL_STATEMENT_NAME("26000"),
/**
* Attempted to refer to a statement that should have been prepared,
but was not.
*/
INVALID_SQL_STATEMENT_IDENTIFIER("30000"),
/**
* An error occurred specifying a target for data.
*/
INVALID_TARGET_TYPE_SPECIFICATION("0D000"),
/**
* The operation violated the transaction constraints.
*/
INVALID_TRANSACTION_STATE("25000"),
/**
* START TRANSACTION or DISCONNECT or SET SESSION AUTHORIZATION or
SET ROLE statements cannot be
* issued if a transaction has already been started.
*/
ACTIVE_SQL_TRANSACTION("25001"),
/**
* SET TRANSACTION LOCAL ..., which applies only in multiple-server
contexts, is illegal if a
* local transaction is already happening.
*/
BRANCH_TRANSACTION_ALREADY_ACTIVE("25002"),
/**
* The SET TRANSACTION statement cannot be used to change isolation
level if there is a held
* Cursor made with a different isolation level left over from the
last transaction.
*/
HELD_CURSOR_REQUIRES_SAME_ISOLATION_LEVEL("25008"),
/**
* Returned if the transaction access mode of the SQL-transaction is
read-only and transaction
* access mode specifies READWRITE.
*/
INAPPROPRIATE_ACCESS_MODE_FOR_BRANCH_TRANSACTION("25003"),
/**
* Returned if the isolation level of the SQL-transaction is
SERIALIZABLE and level of isolation
* specifies anything except SERIALIZABLE, or if the isolation level
of the SQL-transaction is
* REPEATABLE READ and level of isolation specifies anything except
REPEATABLE READ or
* SERIALIZABLE, or if the isolation level of the SQL-transaction is
READ COMMITTED and level of
* isolation specifies READ UNCOMMITTED.
*/
INAPPROPRIATE_ISOLATION_LEVEL_FOR_BRANCH_TRANSACTION("25004"),
/**
* Returned if SET LOCAL TRANSACTION is executed and there is no
active transaction.
*/
NO_ACTIVE_SQL_TRANSACTION_FOR_BRANCH_TRANSACTION("25005"),
/**
* An update operation is not valid because the transaction is read-
only.
*/
READ_ONLY_SQL_TRANSACTION("25006"),
/**
* Some DBMSs do not allow SQL-Schema statements (such as CREATE) to
be mixed with SQL-data
* statements (such as INSERT) in the same transaction.
*/
SCHEMA_AND_DATA_STATEMENT_MIXING_NOT_SUPPORTED("25007"),
/**
* An error occurred trying to commit or rollback a transaction.
*/
INVALID_TRANSACTION_TERMINATION("2D000"),
/**
* A <code>Transform Group name</code> could be invalid if it is used
as a qualifier or as the
* argument of SET TRANSFORM GROUP, and does not refer to an existing
Transform Group or is not
* a valid <code>identifier</code>.
*/
INVALID_TRANSFORM_GROUP_NAME_SPECIFICATION("0S000"),
/**
* The "locator exception" class identifies exception conditions that
relate to locators: BLOB
* and CLOB data types, and their values.
*/
LOCATOR_EXCEPTION("0F000"),
/**
* The locator value does not currently represent any value.
*/
INVALID_LOCATOR_SPECIFICATION("0F001"),
/**
* One of the following exceptions occurred:
*
* <ol>
* <li>The result of the SELECT INTO statement or the subselect of
the INSERT statement was an
* empty table.</li>
* <li>The number of rows identified in the searched UPDATE or DELETE
statement was zero./<li>
* <li>The position of the cursor referenced in the FETCH statement
was before the first row or
* after the last row of the result table.</li>
* <li>The fetch orientation is invalid.</li>
* </ol>
*/
NO_DATA("02000"),
/**
* No additional result sets returned.
*/
NO_ADDITIONAL_DYNAMIC_RESULT_SETS_RETURNED("02001"),
/**
* The statement is not allowed in a trigger.
*/
PROHIBITED_STATEMENT_ENCOUNTERED_DURING_TRIGGER("0W000"),
/**
* An error occurred while an SQL-client interacted with an SQL-
server across a communications
* network using an RDA Application Context.
*/
REMOTE_DATABASE_ACCESS("HZ000"),
ATTRIBUTE_NOT_PERMITTED("HZ301"),
AUTHENTICATION_FAILURE("HZ302"),
DUPLICATE_REQUEST_IDENT("HZ303"),
ENCODING_NOT_SUPPORTED("HZ304"),
FEATURE_NOT_SUPPORTED_MULTIPLE_SERVER_TRANSACTIONS("HZ305"),
INVALID_ATTRIBUTE_TYPE("HZ306"),
INVALID_FETCH_COUNT("HZ307"),
INVALID_MESSAGE_TYPE("HZ308"),
INVALID_OPERATION_SEQUENCE("HZ309"),
INVALID_TRANSACTION_OPERATION_CODE("HZ310"),
MISMATCH_BETWEEN_DESCRIPTOR_AND_ROW("HZ311"),
NO_CONNECTION_HANDLE_AVAILABLE("HZ312"),
NUMBER_OF_VALUES_DOES_NOT_MATCH_NUMBER_OF_ITEM_DESCRIPTORS("HZ313"),
TRANSACTION_CANNOT_COMMIT("HZ314"),
TRANSACTION_STATE_UNKNOWN("HZ315"),
TRANSPORT_FAILURE("HZ316"),
UNEXPECTED_PARAMETER_DESCRIPTOR("HZ317"),
UNEXPECTED_ROW_DESCRIPTOR("HZ318"),
UNEXPECTED_ROWS("HZ319"),
VERSION_NOT_SUPPORTED("HZ320"),
TCPIP_ERROR("HZ321"),
TLS_ALERT("HZ322"),
/**
* An error occurred using a savepoint.
*/
SAVEPOINT_EXCEPTION("3B000"),
/**
* The savepoint is not valid.
*/
INVALID_SAVEPOINT_SPECIFICATION("3B001"),
/**
* The maximum number of savepoints has been reached.
*/
TOO_MANY_SAVEPOINTS("3B002"),
/**
* SQL routine is a procedure or function which is written in SQL.
SQLSTATE class 2F identifies
* exception conditions that relate to SQL routines. (Exceptions for
non-SQL routines are class
* 38.)
*/
SQL_ROUTINE_EXCEPTION("2F000"),
/**
* The function did not execute a RETURN statement.
*/
FUNCTION_EXECUTED_NO_RETURN_STATEMENT("2F005"),
/**
* The SQL function attempted to modify data, but the function was
not defined as
* MODIFIES SQL DATA.
*/
MODIFYING_SQL_DATA_NOT_PERMITTED_BY_FUNCTION("2F002"),
/**
* The statement is not allowed in a function or procedure.
*/
PROHIBITED_SQL_STATEMENT_ATTEMPTED_BY_FUNCTION("2F003"),
/**
* The SQL function attempted to read data, but the function was not
defined as READS SQL DATA.
*/
READING_SQL_DATA_NOT_PERMITTED("2F004"),
/**
* Completion of the operation was successful and did not result in
any type of warning or
* exception condition.
*/
SUCCESSFUL_COMPLETION("00000"),
/**
* Syntax errors include not just grammar or spelling errors, but
"bind problems" such as
* failure to find an Object. Access violations are due to lack of
Privileges. A high security
* DBMS will try to hide from the user whether the problem is "you
don't have access to X" as
* opposed to "X isn't there"; that's why these two different
categories are lumped together in
* one SQLSTATE (thus users can't discover what the Table names are
by trying out all the
* possibilities).
*/
SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION("42000"),
/**
* Invoked a dynamic update or delete statement but the cursor
specification conflicts with the
* specification of the table it is operating over.
*/
TARGET_TABLE_DISAGREES_WITH_CURSOR_SPECIFICATION("0T000"),
/**
* An error has triggered a rollback the transaction.
*/
TRANSACTION_ROLLBACK("40000"),
/**
* This occurs for COMMIT, if there were deferred Constraints
(deferred Constraints aren't
* checked until COMMIT time unless SET CONSTRAINTS IMMEDIATE is
executed). So: you asked for
* COMMIT, and what you got was ROLLBACK. See also SQLSTATE 23000.
*/
TRANSACTION_INTEGRITY_CONSTRAINT_VIOLATION("40002"),
/**
* The database engine has detected a deadlock. The transaction of
this session has been rolled
* back to solve the problem. A deadlock occurs when a session tries
to lock a table another
* session has locked, while the other session wants to lock a table
the first session has
* locked. As an example, session 1 has locked table A, while session
2 has locked table B.
* If session 1 now tries to lock table B and session 2 tries to lock
table A, a deadlock has
* occurred. Deadlocks that involve more than two sessions are also
possible. To solve deadlock
* problems, an application should lock tables always in the same
order, such as always lock
* table A before locking table B. For details, see
* <a href="
http://en.wikipedia.org/wiki/Deadlock">Wikipedia
Deadlock</a>.
*/
SERIALIZATION_FAILURE("40001"),
/**
* The SQL-Connection was lost during execution of an SQL statement.
*/
STATEMENT_COMPLETION_UNKNOWN("40003"),
/**
* This occurs for COMMIT, if there was a deferred Constraint —
presumably a FOREIGN KEY
* Constraint unless Triggers are supported by the DBMS — and there
was an attempt to violate the
* Constraint. See also SQLSTATE 09000, 27000.
*/
TRIGGERED_ACTION_EXCEPTION_AT_COMMIT("40004"),
/**
* A triggered SQL statement failed.
*/
TRIGGERED_ACTION_EXCEPTION("09000"),
/**
* An attempt was made to modify the target table of the MERGE
statement by a constraint or
* trigger. See also SQLSTATE 09000, 40004.
*/
TRIGGERED_DATA_CHANGE_VIOLATION("27000"),
/**
* The operation completed with a warning.
*/
WARNING("01000"),
/**
* The cursor that was closed has been reopened on the next result
set within the chain.
*/
ADDITIONAL_RESULT_SETS_RETURNED("0100D"),
/**
* The maximum number of elements in the target array is less than
the number of elements in
* the source array and the extra source elements are all NULL. The
database will assign as many
* of the source element values to the target elements as is
possible.
*/
ARRAY_DATA_RIGHT_TRUNCATION_WARNING("0102F"),
/**
* The procedure returned too many result sets.
*/
TOO_MANY_RESULT_SETS("0100E"),
/**
* Returned if you DELETE with and without a Cursor in the same
transaction.
*/
CURSOR_OPERATION_CONFLICT("01001"),
/**
* This is the same as warning 01009 except that instead of a search
condition (as in a CHECK
* clause), you're using a default value.
*/
DEFAULT_VALUE_TOO_LONG_FOR_INFORMATION_SCHEMA("0100B"),
/**
* There was an error during execution of the CLI function
SQLDisconnect, but you won't be able
* to see the details because the SQLDisconnect succeeded.
*/
DISCONNECT_ERROR("01002"),
/**
* One or more ad hoc result sets were returned from the procedure.
*/
DYNAMIC_RESULT_SETS_RETURNED("0100C"),
/**
* Every descriptor area has multiple IDAs. You need one IDA per
Column of a result set, or one
* per parameter. Either reduce the number of Columns in the select
list or reduce the number of
* ?s in the SQL statement as a whole.
*/
INSUFFICIENT_ITEM_DESCRIPTOR_AREAS("01005"),
/**
* Null values were eliminated from the argument of a column
function.
*/
NULL_VALUE_ELIMINATED_IN_SET_FUNCTION("01003"),
/**
* A privilege was not granted.
*/
PRIVILEGE_NOT_GRANTED("01007"),
/**
* A privilege was not revoked.
*/
PRIVILEGE_NOT_REVOKED("01006"),
/**
* This is the same as warning 01009 except that instead of a search
condition (as in a CHECK
* clause), you're using a query condition (usually SELECT). Thus, if
you say "CREATE VIEW ..."
* with a very long query, the size of Column VIEW_DEFINITION in View
VIEWS in INFORMATION_SCHEMA
* is a limiting factor.
*/
QUERY_EXPRESSION_TOO_LONG_FOR_INFORMATION_SCHEMA("0100A"),
/**
* Suppose you say "CREATE TABLE ... CHECK (<condition>)", and the
length of <condition> is
* larger than what can be stored in the INFORMATION_SCHEMA View,
CHECK_CONSTRAINTS, in its
* CHECK_CLAUSE Column. The Table will still be created — this
warning only means you won't be
* able to see the entire information about the Table when you look
at INFORMATION_SCHEMA. See
* also SQLState 0100A and 0100B.
*/
SEARCH_CONDITION_TOO_LONG_FOR_INFORMATION_SCHEMA("01009"),
/**
* Returned if the character representation of the triggered SQL
statement cannot be represented
* in the Information Schema without truncation.
*/
STATEMENT_TOO_LONG_FOR_INFORMATION_SCHEMA("0100F"),
/**
* The value of a string was truncated when assigned to another
string data type with a shorter
* length.
*/
STRING_DATA_RIGHT_TRUNCATION_ON_READ("01004"),
/**
* The INSERT or UPDATE is not allowed, because a resulting row does
not satisfy the view
* definition.
*/
WITH_CHECK_OPTION_VIOLATION("44000");
private static final Map<String, SQLState> codeToEnum =
Maps.newHashMap();
private final String code;
/**
* Creates a new SQLState.
*
* @param code the 5-character SQLState code
*/
SQLState(String code)
{
this.code = code;
assert (code.length() == 5): code;
}
static
{
for (SQLState value: values())
codeToEnum.put(value.getCode(), value);
}
/**
* Returns the code associated with the enum.
*
* @return the code
*/
public String getCode()
{
return code;
}
/**
* Returns the SQLState associated with the specified code.
*
* @param code the code (5 characters)
* @return the SQLState
* @throws IllegalArgumentException if no enum value is associated
with the specified code
*/
public static SQLState fromCode(String code)
{
SQLState result = codeToEnum.get(code);
if (result == null)
throw new IllegalArgumentException(code);
return result;
}
/**
* Returns the SQLState category.
*
* @return the SQLState category
*/
public Category getCategory()
{
try
{
return Category.fromCode(code.substring(0, 2));
}
catch (IllegalArgumentException e)
{
throw new AssertionError(e);
}
}
public enum Category
{
/**
* If the statement contains a preparable dynamic cursor name that
is ambiguous.
*/
AMBIGUOUS_CURSOR_NAME("3C"),
/**
* Attempted to assign a value to a non-updatable column.
*/
CANNOT_ASSIGN_TO_NON_UPDATABLE_COLUMN("0U"),
/**
* If any object column is directly or indirectly referenced in the
<code>order by</code> clause
* of a dynamic cursor definition.
*/
CANNOT_ASSIGN_TO_ORDERING_COLUMN("0V"),
/**
* The result of a SELECT INTO, scalar fullselect, or subquery of a
basic predicate returned more
* than one value.
*/
CARDINALITY_VIOLATION("21"),
/**
* Unable to establish a database connection.
*/
CONNECTION_EXCEPTION("08"),
/**
* The "cursor sensitivity exception" class identifies exception
conditions that relate to Cursors
* and their sensitivity attribute.
*/
CURSOR_SENSITIVITY_EXCEPTION("36"),
/**
* The specified data was inappropriate for the column type.
*/
DATA_EXCEPTION("22"),
/**
* Attempted to "REVOKE GRANT OPTION FOR" with dependent privileges
and without a "CASCADE".
*/
DEPENDENT_PRIVILEGE_DESCRIPTORS_STILL_EXIST("2B"),
/**
* An error occurred while invoking a diagnostics function.
*/
DIAGNOSTICS_EXCEPTION("0Z"),
/**
* An error occurred while executing dynamic SQL.
*/
DYNAMIC_SQL_ERROR("07"),
/**
* An error occurred executing an external routine.
*
* External routines are stored procedures implemented by non-SQL
languages (i.e. Java).
*/
EXTERNAL_ROUTINE_EXCEPTION("38"),
/**
* An error occurred before or after invoking an external routine.
*
* External routines are stored procedures implemented by non-SQL
languages (i.e. Java).
*/
EXTERNAL_ROUTINE_INVOCATION_EXCEPTION("39"),
/**
* The specified feature is not supported.
*/
FEATURE_NOT_SUPPORTED("0A"),
/**
* The operation violated a table constraint.
*/
INTEGRITY_CONSTRAINT_VIOLATION("23"),
/**
* Authorization name is invalid.
*/
INVALID_AUTHORIZATION_SPECIFICATION("28"),
/**
* A <code>Catalog name</code> could be invalid if it is used as a
qualifier or as the
* argument of SET CATALOG, and does not refer to an existing
Catalog or is not a valid
* <code>identifier</code>.
*/
INVALID_CATALOG_NAME("3D"),
/**
* Presumably an invalid Character set name would be one that begins
with a digit, contains a
* non-Latin letter, etc.
*/
INVALID_CHARACTER_SET_NAME("2C"),
/**
* With embedded SQL, you get this by saying "GET DIAGNOSTICS
EXCEPTION 0". With the CLI, you get
* this by calling SQLGetDiagRec or SQLGetDiagField with a
RecordNumber parameter less than 1.
* If RecordNumber is greater than the number of status records, you
don't get this error.
* Instead, you get an NO_DATA return code.
*/
INVALID_CONDITION_NUMBER("35"),
/**
* For a CONNECT statement, the argument must be a valid
<code>identifier</code>.
*/
INVALID_CONNECTION_NAME("2E"),
/**
* Cursor name is invalid.
*/
INVALID_CURSOR_NAME("34"),
/**
* The cursor is closed or has no current row.
*/
INVALID_CURSOR_STATE("24"),
/**
* The specified grantor may not GRANT access.
*/
INVALID_GRANTOR("0L"),
/**
* Invalid role specification. The specified role does not exist or
is not granted to the
* specified user.
*/
INVALID_ROLE_SPECIFICATION("0P"),
/**
* The schema (collection) name is invalid.
*/
INVALID_SCHEMA_NAME("3F"),
/**
* An error occurred while specifying Schema paths.
*/
INVALID_SCHEMA_NAME_LIST_SPECIFICATION("0E"),
/**
* A <code>Collation name</code> could be invalid if it is used as a
qualifier or as the
* argument of SET COLLATION, and does not refer to an existing
Collation or is not a valid
* <code>identifier</code>.
*/
INVALID_COLLATION_NAME("2H"),
/**
* Returned if, in embedded SQL, you use "EXECUTE ... USING
DESCRIPTOR 'X';", a descriptor named
* X must exist.
*/
INVALID_SQL_DESCRIPTOR_NAME("33"),
/**
* Returned if the SQL-session context of the current SQL-session
does not include a result set
* sequence brought into existence by an invocation of SQL-invoked
procedure by the active
* SQL-invoked routine.
*/
INVALID_SQL_INVOKED_PROCEDURE_REFERENCE("0M"),
/**
* Probable cause: you failed to PREPARE an SQL statement and now
you are trying to EXECUTE it.
*/
INVALID_SQL_STATEMENT_NAME("26"),
/**
* Attempted to refer to a statement that should have been prepared,
but was not.
*/
INVALID_SQL_STATEMENT_IDENTIFIER("30"),
/**
* An error occurred specifying a target for data.
*/
INVALID_TARGET_TYPE_SPECIFICATION("0D"),
/**
* The operation violated transaction constraints.
*/
INVALID_TRANSACTION_STATE("25"),
/**
* An error occurred trying to commit or rollback a transaction.
*/
INVALID_TRANSACTION_TERMINATION("2D"),
/**
* A <code>Transform Group name</code> could be invalid if it is
used as a qualifier or as the
* argument of SET TRANSFORM GROUP, and does not refer to an
existing Transform Group or is not
* a valid <code>identifier</code>.
*/
INVALID_TRANSFORM_GROUP_NAME_SPECIFICATION("0S"),
/**
* The "locator exception" class identifies exception conditions
that relate to locators: BLOB
* and CLOB data types, and their values.
*/
LOCATOR_EXCEPTION("0F"),
/**
* The operation did not return any data.
*/
NO_MORE_DATA("02"),
/**
* The statement is not allowed in a trigger.
*/
PROHIBITED_STATEMENT_ENCOUNTERED_DURING_TRIGGER("0W"),
/**
* An error occurred while an SQL-client interacted with an SQL-
server across a communications
* network using an RDA Application Context.
*/
REMOTE_DATABASE_ACCESS("HZ"),
/**
* An error occurred using a savepoint.
*/
SAVEPOINT_EXCEPTION("3B"),
/**
* SQL routine is a procedure or function which is written in SQL.
SQLSTATE class 2F identifies
* exception conditions that relate to SQL routines. (Exceptions for
non-SQL routines are class
* 38.)
*/
SQL_ROUTINE_EXCEPTION("2F"),
/**
* Completed successfully.
*/
SUCCESS("00"),
/**
* Syntax errors include not just grammar or spelling errors, but
"bind problems" such as
* failure to find an Object. Access violations are due to lack of
Privileges. A high security
* DBMS will try to hide from the user whether the problem is "you
don't have access to X" as
* opposed to "X isn't there"; that's why these two different
categories are lumped together in
* one SQLSTATE (thus users can't discover what the Table names are
by trying out all the
* possibilities).
*/
SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION("42"),
/**
* Invoked a dynamic update or delete statement but the cursor
specification conflicts with the
* specification of the table it is operating over.
*/
TARGET_TABLE_DISAGREES_WITH_CURSOR_SPECIFICATION("0T"),
/**
* An error has triggered a rollback the transaction.
*/
TRANSACTION_ROLLBACK("40"),
/**
* A triggered SQL statement failed.
*/
TRIGGERED_ACTION_EXCEPTION("09"),
/**
* An attempt was made to modify the target table of the MERGE
statement by a constraint or
* trigger. See also SQLSTATE 09000, 40004.
*/
TRIGGERED_DATA_CHANGE_VIOLATION("27"),
/**
* Completed with a warning.
*/
WARNING("01"),
/**
* The INSERT or UPDATE is not allowed, because a resulting row does
not satisfy the view
* definition.
*/
WITH_CHECK_OPTION_VIOLATION("44");
private final String code;
private static final Map<String, Category> codeToEnum =
Maps.newHashMap();
/**
* Creates a new Category.
*
* @param code the 2-character Category code
*/
Category(String code)
{
this.code = code;
assert (code.length() == 2): code;
}
static
{
for (Category value: values())
codeToEnum.put(value.getCode(), value);
}
/**
* Returns the code associated with the enum.
*
* @return the code
*/
public String getCode()
{
return code;
}
/**
* Returns the Category associated with the specified code.
*
* @param code the category code (2 characters)
* @return the Category
* @throws IllegalArgumentException if no enum value is associated
with the specified code
*/
public static Category fromCode(String code)
{
Category result = codeToEnum.get(code);
if (result == null)
throw new IllegalArgumentException(code);
return result;
}
};
}
-------------------------------