home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / java / sql / SQLException.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  4.5 KB  |  166 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)SQLException.java    1.16 98/09/29
  3.  *
  4.  * Copyright 1996-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.sql;
  16.  
  17. /**
  18.  * <P>An exception that provides information on a database access
  19.  * error.
  20.  *
  21.  * <P>Each <code>SQLException</code> provides several kinds of information: 
  22.  * <UL>
  23.  *   <LI> a string describing the error.  This is used as the Java Exception
  24.  *       message, available via the method <code>getMesage</code>.
  25.  *   <LI> a "SQLstate" string, which follows the XOPEN SQLstate conventions.
  26.  *       The values of the SQLState string are described in the XOPEN SQL spec.
  27.  *   <LI> an integer error code that is specific to each vendor.  Normally this will
  28.  *     be the actual error code returned by the underlying database.
  29.  *   <LI> a chain to a next Exception.  This can be used to provide additional
  30.  *      error information.
  31.  * </UL>
  32.  */
  33. public class SQLException extends java.lang.Exception {
  34.  
  35.     /**
  36.      * Constructs a fully-specified <code>SQLException</code> object.  
  37.      *
  38.      * @param reason a description of the exception 
  39.      * @param SQLState an XOPEN code identifying the exception
  40.      * @param vendorCode a database vendor-specific exception code
  41.      */
  42.     public SQLException(String reason, String SQLState, int vendorCode) {
  43.     super(reason);
  44.     this.SQLState = SQLState;
  45.     this.vendorCode = vendorCode;
  46.     if (!(this instanceof SQLWarning)) {
  47.         if (DriverManager.getLogStream() != null) {
  48.         DriverManager.println("SQLException: SQLState(" + SQLState + 
  49.                         ") vendor code(" + vendorCode + ")");
  50.         printStackTrace(DriverManager.getLogStream());
  51.         }
  52.     }
  53.     }
  54.  
  55.  
  56.     /**
  57.      * Constructs an <code>SQLException</code> object with a reason and SQLState;
  58.      * vendorCode defaults to 0.
  59.      *
  60.      * @param reason a description of the exception 
  61.      * @param SQLState an XOPEN code identifying the exception 
  62.      */
  63.     public SQLException(String reason, String SQLState) {
  64.     super(reason);
  65.     this.SQLState = SQLState;
  66.     this.vendorCode = 0;
  67.     if (!(this instanceof SQLWarning)) {
  68.         if (DriverManager.getLogStream() != null) {
  69.         printStackTrace(DriverManager.getLogStream());
  70.         DriverManager.println("SQLException: SQLState(" + SQLState + ")");
  71.         }
  72.     }
  73.     }
  74.  
  75.     /**
  76.      * Constructs an <code>SQLException</code> object with a reason;
  77.      * SQLState defaults to null, and vendorCode defaults to 0.
  78.      *
  79.      * @param reason a description of the exception 
  80.      */
  81.     public SQLException(String reason) {
  82.     super(reason);
  83.     this.SQLState = null;
  84.     this.vendorCode = 0;
  85.     if (!(this instanceof SQLWarning)) {
  86.         if (DriverManager.getLogStream() != null) {
  87.         printStackTrace(DriverManager.getLogStream());
  88.         }
  89.     }
  90.     }
  91.  
  92.     /**
  93.      * Constructs an <code>SQLException</code> object;
  94.      * reason defaults to null, SQLState
  95.      * defaults to null, and vendorCode defaults to 0.
  96.      * */
  97.     public SQLException() {
  98.     super();
  99.     this.SQLState = null;
  100.     this.vendorCode = 0;
  101.     if (!(this instanceof SQLWarning)) {
  102.         if (DriverManager.getLogStream() != null) {
  103.         printStackTrace(DriverManager.getLogStream());
  104.         }
  105.     }
  106.     }
  107.  
  108.     /**
  109.      * Retrieves the SQLState for this <code>SQLException</code> object.
  110.      *
  111.      * @return the SQLState value
  112.      */
  113.     public String getSQLState() {
  114.     return (SQLState);
  115.     }    
  116.  
  117.     /**
  118.      * Retrieves the vendor-specific exception code
  119.      * for this <code>SQLException</code> object.
  120.      *
  121.      * @return the vendor's error code
  122.      */
  123.     public int getErrorCode() {
  124.     return (vendorCode);
  125.     }
  126.  
  127.     /**
  128.      * Retrieves the exception chained to this 
  129.      * <code>SQLException</code> object.
  130.      *
  131.      * @return the next SQLException in the chain; null if none
  132.      */
  133.     public SQLException getNextException() {
  134.     return (next);
  135.     }
  136.  
  137.     /**
  138.      * Adds an <code>SQLException</code> object to the end of the chain.
  139.      *
  140.      * @param ex the new exception that will be added to the end of
  141.      *            the SQLException chain
  142.      */
  143.     public synchronized void setNextException(SQLException ex) {
  144.     SQLException theEnd = this;
  145.     while (theEnd.next != null) {
  146.         theEnd = theEnd.next;
  147.     }
  148.     theEnd.next = ex;
  149.     }
  150.  
  151.     /**
  152.      * @serial
  153.      */
  154.     private String SQLState;
  155.  
  156.     /**
  157.      * @serial
  158.      */
  159.     private int vendorCode;
  160.  
  161.     /**
  162.      * @serial
  163.      */
  164.     private SQLException next;
  165. }
  166.