Package java.sql
Class SQLException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.sql.SQLException
- All Implemented Interfaces:
Serializable,Iterable<Throwable>
- Direct Known Subclasses:
BatchUpdateException,SQLClientInfoException,SQLNonTransientException,SQLRecoverableException,SQLTransientException,SQLWarning
public class SQLException extends Exception implements Serializable, Iterable<Throwable>
An exception that indicates a failed JDBC operation.
It provides the following information about problems encountered with
database access:
- A message string.
- A
SQLStateerror description string following either SQL 99 or X/OPENSQLStateconventions.DatabaseMetaData.getSQLStateType()exposes the specific convention in use. - A database-specific error code.
- The next exception in the chain.
- See Also:
DatabaseMetaData, Serialized Form
-
Constructor Summary
Constructors Constructor Description SQLException()Creates anSQLExceptionobject.SQLException(String theReason)Creates anSQLExceptionobject.SQLException(String theReason, String theSQLState)Creates anSQLExceptionobject.SQLException(String theReason, String theSQLState, int theErrorCode)Creates anSQLExceptionobject.SQLException(String theReason, String theSQLState, int theErrorCode, Throwable theCause)Creates an SQLException object.SQLException(String theReason, String theSQLState, Throwable theCause)Creates an SQLException object.SQLException(String theReason, Throwable theCause)Creates an SQLException object.SQLException(Throwable theCause)Creates an SQLException object. -
Method Summary
Modifier and Type Method Description intgetErrorCode()Returns the integer error code for thisSQLException.SQLExceptiongetNextException()Retrieves theSQLExceptionchained to thisSQLException, if any.StringgetSQLState()Retrieves theSQLStatedescription string for thisSQLExceptionobject.Iterator<Throwable>iterator()Obsolete.voidsetNextException(SQLException ex)Obsolete.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
SQLException
public SQLException()Creates anSQLExceptionobject. The reason string is set tonull, theSQLStatestring is set tonulland the error code is set to 0. -
SQLException
Creates anSQLExceptionobject. The reason string is set to the given reason string, theSQLStatestring is set tonulland the error code is set to 0.- Parameters:
theReason- the string to use as the Reason string
-
SQLException
Creates anSQLExceptionobject. The reason string is set to the given reason string, theSQLStatestring is set to the givenSQLStatestring and the error code is set to 0.- Parameters:
theReason- the string to use as the reason string.theSQLState- the string to use as theSQLStatestring.
-
SQLException
Creates anSQLExceptionobject. The reason string is set to the given reason string, theSQLStatestring is set to the givenSQLStatestring and the error code is set to the given error code value.- Parameters:
theReason- the string to use as the reason string.theSQLState- the string to use as theSQLStatestring.theErrorCode- the integer value for the error code.
-
SQLException
Creates an SQLException object. The Reason string is set to the null if cause == null or cause.toString() if cause!=null,and the cause Throwable object is set to the given cause Throwable object.- Parameters:
theCause- the Throwable object for the underlying reason this SQLException- Since:
- 1.6
-
SQLException
Creates an SQLException object. The Reason string is set to the given and the cause Throwable object is set to the given cause Throwable object.- Parameters:
theReason- the string to use as the Reason stringtheCause- the Throwable object for the underlying reason this SQLException- Since:
- 1.6
-
SQLException
Creates an SQLException object. The Reason string is set to the given reason string, the SQLState string is set to the given SQLState string and the cause Throwable object is set to the given cause Throwable object.- Parameters:
theReason- the string to use as the Reason stringtheSQLState- the string to use as the SQLState stringtheCause- the Throwable object for the underlying reason this SQLException- Since:
- 1.6
-
SQLException
Creates an SQLException object. The Reason string is set to the given reason string, the SQLState string is set to the given SQLState string , the Error Code is set to the given error code value, and the cause Throwable object is set to the given cause Throwable object.- Parameters:
theReason- the string to use as the Reason stringtheSQLState- the string to use as the SQLState stringtheErrorCode- the integer value for the error codetheCause- the Throwable object for the underlying reason this SQLException- Since:
- 1.6
-
-
Method Details
-
getErrorCode
public int getErrorCode()Returns the integer error code for thisSQLException.- Returns:
- The integer error code for this
SQLException. The meaning of the code is specific to the vendor of the database.
-
getNextException
Retrieves theSQLExceptionchained to thisSQLException, if any.- Returns:
- The
SQLExceptionchained to thisSQLException.nullif there is noSQLExceptionchained to thisSQLException.
-
getSQLState
Retrieves theSQLStatedescription string for thisSQLExceptionobject.- Returns:
- The
SQLStatestring for thisSQLExceptionobject. This is an error description string which follows either the SQL 99 conventions or the X/OPENSQLstateconventions. The potential values of theSQLStatestring are described in each of the specifications. Which of the conventions is being used by theSQLStatestring can be discovered by using thegetSQLStateTypemethod of theDatabaseMetaDatainterface.
-
setNextException
Obsolete. Appendsexto the end of this chain. -
iterator
Obsolete.Throwable.getCause()should be used instead of this iterator. Returns an iterator over the exceptions added withsetNextException(java.sql.SQLException).
-