public class

SQLException

extends Exception
implements Serializable
java.lang.Object
   ↳ java.lang.Throwable
     ↳ java.lang.Exception
       ↳ java.sql.SQLException
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

An Exception class that is used in conjunction with JDBC operations. It provides information about problems encountered with database access and other problems related to JDBC

The SQLException class provides the following information:

  • A standard Java exception message, as a String
  • An SQLState string. This is an error description string which follows either the SQL 99 conventions or the X/OPEN SQLstate conventions. The potential values of the SQLState string are described in each of the specifications. Which of the conventions is being used by the SQLState string can be discovered by using the getSQLStateType method of the DatabaseMetaData interface.
  • An error code, an an integer. The error code is specific to each database vendor and is typically the error code returned by the database itself.
  • A chain to a next Exception, if relevant, which can give access to additional error information.

See Also

Summary

Public Constructors
SQLException()
Creates an SQLException object.
SQLException(String theReason)
Creates an SQLException object.
SQLException(String theReason, String theSQLState)
Creates an SQLException object.
SQLException(String theReason, String theSQLState, int theErrorCode)
Creates an SQLException object.
Public Methods
int getErrorCode()
Returns the integer error code for this SQLException.
SQLException getNextException()
Retrieves the SQLException chained to this SQLException, if any.
String getSQLState()
Retrieves the SQLState description string for this SQLException object.
void setNextException(SQLException ex)
Adds the SQLException to the end of this SQLException chain.
[Expand]
Inherited Methods
From class java.lang.Throwable
From class java.lang.Object

Public Constructors

public SQLException ()

Since: API Level 1

Creates an SQLException object. The reason string is set to null, the SQLState string is set to null and the error code is set to 0.

public SQLException (String theReason)

Since: API Level 1

Creates an SQLException object. The reason string is set to the given reason string, the SQLState string is set to null and the error code is set to 0.

Parameters
theReason the string to use as the Reason string

public SQLException (String theReason, String theSQLState)

Since: API Level 1

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 error code is set to 0.

Parameters
theReason the string to use as the reason string.
theSQLState the string to use as the SQLState string.

public SQLException (String theReason, String theSQLState, int theErrorCode)

Since: API Level 1

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 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 the SQLState string.
theErrorCode the integer value for the error code.

Public Methods

public int getErrorCode ()

Since: API Level 1

Returns the integer error code for this SQLException.

Returns
  • The integer error code for this SQLException. The meaning of the code is specific to the vendor of the database.

public SQLException getNextException ()

Since: API Level 1

Retrieves the SQLException chained to this SQLException, if any.

Returns
  • The SQLException chained to this SQLException. null if there is no SQLException chained to this SQLException.

public String getSQLState ()

Since: API Level 1

Retrieves the SQLState description string for this SQLException object.

Returns
  • The SQLState string for this SQLException object. This is an error description string which follows either the SQL 99 conventions or the X/OPEN SQLstate conventions. The potential values of the SQLState string are described in each of the specifications. Which of the conventions is being used by the SQLState string can be discovered by using the getSQLStateType method of the DatabaseMetaData interface.

public void setNextException (SQLException ex)

Since: API Level 1

Adds the SQLException to the end of this SQLException chain.

Parameters
ex the new SQLException to be added to the end of the chain.