home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / SQLException.java < prev    next >
Text File  |  1997-05-20  |  5KB  |  159 lines

  1. /*
  2.  * @(#)SQLException.java    1.5 96/11/23
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  * 
  21.  */
  22.  
  23. package java.sql;
  24.  
  25. /**
  26.  * <P>The SQLException class provides information on a database access
  27.  * error.
  28.  *
  29.  * <P>Each SQLException provides several kinds of information: 
  30.  * <UL>
  31.  *   <LI> a string describing the error.  This is used as the Java Exception
  32.  *       message, and is available via the getMesage() method
  33.  *   <LI> A "SQLstate" string which follows the XOPEN SQLstate conventions.
  34.  *       The values of the SQLState string as described in the XOPEN SQL spec.
  35.  *   <LI> An integer error code that is vendor specific.  Normally this will
  36.  *     be the actual error code returned by the underlying database.
  37.  *   <LI> A chain to a next Exception.  This can be used to provided additional
  38.  *      error information.
  39.  * </UL>
  40.  */
  41. public class SQLException extends java.lang.Exception {
  42.  
  43.     /**
  44.      * Construct a fully-specified SQLException  
  45.      *
  46.      * @param reason a description of the exception 
  47.      * @param SQLState an XOPEN code identifying the exception
  48.      * @param vendorCode a database vendor specific exception code
  49.      */
  50.     public SQLException(String reason, String SQLState, int vendorCode) {
  51.     super(reason);
  52.     this.SQLState = SQLState;
  53.     this.vendorCode = vendorCode;
  54.     if (!(this instanceof SQLWarning)) {
  55.         if (DriverManager.getLogStream() != null) {
  56.         DriverManager.println("SQLException: SQLState(" + SQLState + 
  57.                         ") vendor code(" + vendorCode + ")");
  58.         printStackTrace(DriverManager.getLogStream());
  59.         }
  60.     }
  61.     }
  62.  
  63.  
  64.     /**
  65.      * Construct an SQLException with a reason and SQLState;
  66.      * vendorCode defaults to 0.
  67.      *
  68.      * @param reason a description of the exception 
  69.      * @param SQLState an XOPEN code identifying the exception 
  70.      */
  71.     public SQLException(String reason, String SQLState) {
  72.     super(reason);
  73.     this.SQLState = SQLState;
  74.     this.vendorCode = 0;
  75.     if (!(this instanceof SQLWarning)) {
  76.         if (DriverManager.getLogStream() != null) {
  77.         printStackTrace(DriverManager.getLogStream());
  78.         DriverManager.println("SQLException: SQLState(" + SQLState + ")");
  79.         }
  80.     }
  81.     }
  82.  
  83.     /**
  84.      * Construct an SQLException with a reason; SQLState defaults to
  85.      * null and vendorCode defaults to 0.
  86.      *
  87.      * @param reason a description of the exception 
  88.      */
  89.     public SQLException(String reason) {
  90.     super(reason);
  91.     this.SQLState = null;
  92.     this.vendorCode = 0;
  93.     if (!(this instanceof SQLWarning)) {
  94.         if (DriverManager.getLogStream() != null) {
  95.         printStackTrace(DriverManager.getLogStream());
  96.         }
  97.     }
  98.     }
  99.  
  100.     /**
  101.      * Construct an SQLException; reason defaults to null, SQLState
  102.      * defaults to null and vendorCode defaults to 0.
  103.      * */
  104.     public SQLException() {
  105.     super();
  106.     this.SQLState = null;
  107.     this.vendorCode = 0;
  108.     if (!(this instanceof SQLWarning)) {
  109.         if (DriverManager.getLogStream() != null) {
  110.         printStackTrace(DriverManager.getLogStream());
  111.         }
  112.     }
  113.     }
  114.  
  115.     /**
  116.      * Get the SQLState
  117.      *
  118.      * @return the SQLState value
  119.      */
  120.     public String getSQLState() {
  121.     return (SQLState);
  122.     }    
  123.  
  124.     /**
  125.      * Get the vendor specific exception code
  126.      *
  127.      * @return the vendor's error code
  128.      */
  129.     public int getErrorCode() {
  130.     return (vendorCode);
  131.     }
  132.  
  133.     /**
  134.      * Get the exception chained to this one. 
  135.      *
  136.      * @return the next SQLException in the chain, null if none
  137.      */
  138.     public SQLException getNextException() {
  139.     return (next);
  140.     }
  141.  
  142.     /**
  143.      * Add an SQLException to the end of the chain.
  144.      *
  145.      * @param ex the new end of the SQLException chain
  146.      */
  147.     public synchronized void setNextException(SQLException ex) {
  148.     SQLException theEnd = this;
  149.     while (theEnd.next != null) {
  150.         theEnd = theEnd.next;
  151.     }
  152.     theEnd.next = ex;
  153.     }
  154.  
  155.     private String SQLState;
  156.     private int vendorCode;
  157.     private SQLException next;
  158. }
  159.