FileDocCategorySizeDatePackage
SQLException.javaAPI DocJava SE 5 API4943Fri Aug 26 14:57:20 BST 2005java.sql

SQLException

public class SQLException extends Exception

An exception that provides information on a database access error or other errors.

Each SQLException provides several kinds of information:

  • a string describing the error. This is used as the Java Exception message, available via the method getMesage.
  • a "SQLstate" string, which follows either the XOPEN SQLstate conventions or the SQL 99 conventions. The values of the SQLState string are described in the appropriate spec. The DatabaseMetaData method getSQLStateType can be used to discover whether the driver returns the XOPEN type or the SQL 99 type.
  • an integer error code that is specific to each vendor. Normally this will be the actual error code returned by the underlying database.
  • a chain to a next Exception. This can be used to provide additional error information.

Fields Summary
private String
SQLState
private int
vendorCode
private SQLException
next
Constructors Summary
public SQLException(String reason, String SQLState, int vendorCode)
Constructs a fully-specified SQLException object.

param
reason a description of the exception
param
SQLState an XOPEN or SQL 99 code identifying the exception
param
vendorCode a database vendor-specific exception code

	super(reason);
	this.SQLState = SQLState;
	this.vendorCode = vendorCode;
	if (!(this instanceof SQLWarning)) {
	    if (DriverManager.getLogWriter() != null) {
		DriverManager.println("SQLException: SQLState(" + SQLState + 
						") vendor code(" + vendorCode + ")");
		printStackTrace(DriverManager.getLogWriter());
	    }
	}
    
public SQLException(String reason, String SQLState)
Constructs an SQLException object with the given reason and SQLState; the vendorCode field defaults to 0.

param
reason a description of the exception
param
SQLState an XOPEN or SQL 99 code identifying the exception

	super(reason);
	this.SQLState = SQLState;
	this.vendorCode = 0;
	if (!(this instanceof SQLWarning)) {
	    if (DriverManager.getLogWriter() != null) {
		printStackTrace(DriverManager.getLogWriter());
		DriverManager.println("SQLException: SQLState(" + SQLState + ")");
	    }
	}
    
public SQLException(String reason)
Constructs an SQLException object with a reason; the SQLState field defaults to null, and the vendorCode field defaults to 0.

param
reason a description of the exception

	super(reason);
	this.SQLState = null;
	this.vendorCode = 0;
	if (!(this instanceof SQLWarning)) {
	    if (DriverManager.getLogWriter() != null) {
		printStackTrace(DriverManager.getLogWriter());
	    }
	}
    
public SQLException()
Constructs an SQLException object; the reason field defaults to null, the SQLState field defaults to null, and the vendorCode field defaults to 0.

	super();
	this.SQLState = null;
	this.vendorCode = 0;
	if (!(this instanceof SQLWarning)) {
	    if (DriverManager.getLogWriter() != null) {
		printStackTrace(DriverManager.getLogWriter());
	    }
	}
    
Methods Summary
public intgetErrorCode()
Retrieves the vendor-specific exception code for this SQLException object.

return
the vendor's error code

	return (vendorCode);
    
public java.sql.SQLExceptiongetNextException()
Retrieves the exception chained to this SQLException object.

return
the next SQLException object in the chain; null if there are none
see
#setNextException

	return (next);
    
public java.lang.StringgetSQLState()
Retrieves the SQLState for this SQLException object.

return
the SQLState value

	return (SQLState);
    
public synchronized voidsetNextException(java.sql.SQLException ex)
Adds an SQLException object to the end of the chain.

param
ex the new exception that will be added to the end of the SQLException chain
see
#getNextException

	SQLException theEnd = this;
	while (theEnd.next != null) {
	    theEnd = theEnd.next;
	}
	theEnd.next = ex;