/* * @(#)SQLException.java 1.27 03/12/19 * * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package java.sql; /** *
An exception that provides information on a database access * error or other errors. * *
Each SQLException
provides several kinds of information:
*
getMesage
.
* DatabaseMetaData
method getSQLStateType
* can be used to discover whether the driver returns the XOPEN type or
* the SQL 99 type.
* 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
*/
public SQLException(String reason, String SQLState, int vendorCode) {
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());
}
}
}
/**
* 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
*/
public SQLException(String reason, String SQLState) {
super(reason);
this.SQLState = SQLState;
this.vendorCode = 0;
if (!(this instanceof SQLWarning)) {
if (DriverManager.getLogWriter() != null) {
printStackTrace(DriverManager.getLogWriter());
DriverManager.println("SQLException: SQLState(" + SQLState + ")");
}
}
}
/**
* 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
*/
public SQLException(String reason) {
super(reason);
this.SQLState = null;
this.vendorCode = 0;
if (!(this instanceof SQLWarning)) {
if (DriverManager.getLogWriter() != null) {
printStackTrace(DriverManager.getLogWriter());
}
}
}
/**
* Constructs an SQLException
object;
* the reason
field defaults to null,
* the SQLState
field defaults to null
, and
* the vendorCode
field defaults to 0.
*
*/
public SQLException() {
super();
this.SQLState = null;
this.vendorCode = 0;
if (!(this instanceof SQLWarning)) {
if (DriverManager.getLogWriter() != null) {
printStackTrace(DriverManager.getLogWriter());
}
}
}
/**
* Retrieves the SQLState for this SQLException
object.
*
* @return the SQLState value
*/
public String getSQLState() {
return (SQLState);
}
/**
* Retrieves the vendor-specific exception code
* for this SQLException
object.
*
* @return the vendor's error code
*/
public int getErrorCode() {
return (vendorCode);
}
/**
* Retrieves the exception chained to this
* SQLException
object.
*
* @return the next SQLException
object in the chain;
* null
if there are none
* @see #setNextException
*/
public SQLException getNextException() {
return (next);
}
/**
* 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
*/
public synchronized void setNextException(SQLException ex) {
SQLException theEnd = this;
while (theEnd.next != null) {
theEnd = theEnd.next;
}
theEnd.next = ex;
}
/**
* @serial
*/
private String SQLState;
/**
* @serial
*/
private int vendorCode;
/**
* @serial
*/
private SQLException next;
}