home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / VCAFE.3.0A / Main.bin / SQLException.java < prev    next >
Text File  |  1998-09-22  |  4KB  |  151 lines

  1. /*
  2.  * @(#)SQLException.java    1.6 98/07/01
  3.  *
  4.  * Copyright 1995-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>The SQLException class provides information on a database access
  19.  * error.
  20.  *
  21.  * <P>Each SQLException provides several kinds of information: 
  22.  * <UL>
  23.  *   <LI> a string describing the error.  This is used as the Java Exception
  24.  *       message, and is available via the getMesage() method
  25.  *   <LI> A "SQLstate" string which follows the XOPEN SQLstate conventions.
  26.  *       The values of the SQLState string as described in the XOPEN SQL spec.
  27.  *   <LI> An integer error code that is vendor specific.  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 provided additional
  30.  *      error information.
  31.  * </UL>
  32.  */
  33. public class SQLException extends java.lang.Exception {
  34.  
  35.     /**
  36.      * Construct a fully-specified SQLException  
  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.      * Construct an SQLException 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.      * Construct an SQLException with a reason; SQLState defaults to
  77.      * 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.      * Construct an SQLException; reason defaults to null, SQLState
  94.      * defaults to null and vendorCode defaults to 0.
  95.      * */
  96.     public SQLException() {
  97.     super();
  98.     this.SQLState = null;
  99.     this.vendorCode = 0;
  100.     if (!(this instanceof SQLWarning)) {
  101.         if (DriverManager.getLogStream() != null) {
  102.         printStackTrace(DriverManager.getLogStream());
  103.         }
  104.     }
  105.     }
  106.  
  107.     /**
  108.      * Get the SQLState
  109.      *
  110.      * @return the SQLState value
  111.      */
  112.     public String getSQLState() {
  113.     return (SQLState);
  114.     }    
  115.  
  116.     /**
  117.      * Get the vendor specific exception code
  118.      *
  119.      * @return the vendor's error code
  120.      */
  121.     public int getErrorCode() {
  122.     return (vendorCode);
  123.     }
  124.  
  125.     /**
  126.      * Get the exception chained to this one. 
  127.      *
  128.      * @return the next SQLException in the chain, null if none
  129.      */
  130.     public SQLException getNextException() {
  131.     return (next);
  132.     }
  133.  
  134.     /**
  135.      * Add an SQLException to the end of the chain.
  136.      *
  137.      * @param ex the new end of the SQLException chain
  138.      */
  139.     public synchronized void setNextException(SQLException ex) {
  140.     SQLException theEnd = this;
  141.     while (theEnd.next != null) {
  142.         theEnd = theEnd.next;
  143.     }
  144.     theEnd.next = ex;
  145.     }
  146.  
  147.     private String SQLState;
  148.     private int vendorCode;
  149.     private SQLException next;
  150. }
  151.