home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / JDBC / JDBC_011 / JDBC-011.ZIP / jdbc / java / sql / SQLException.java < prev    next >
Encoding:
Java Source  |  1996-11-10  |  5.0 KB  |  164 lines

  1. /*
  2.  * Copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved.
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software
  5.  * and its documentation for NON-COMMERCIAL purposes and without
  6.  * fee is hereby granted provided that this copyright notice
  7.  * appears in all copies. Please refer to the file "LICENSE"
  8.  * for further important copyright and licensing information.
  9.  *
  10.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  11.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  12.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  13.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  14.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  15.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  16.  * 
  17.  * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
  18.  * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
  19.  * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
  20.  * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
  21.  * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
  22.  * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
  23.  * PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES").  SUN
  24.  * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
  25.  * HIGH RISK ACTIVITIES.
  26.  */
  27.  
  28. package java.sql;
  29.  
  30. /**
  31.  * <P>The SQLException class provides information on a database access
  32.  * error.
  33.  *
  34.  * <P>Each SQLException provides several kinds of information: 
  35.  * <UL>
  36.  *   <LI> a string describing the error.  This is used as the Java Exception
  37.  *       message, and is available via the getMesage() method
  38.  *   <LI> A "SQLstate" string which follows the XOPEN SQLstate conventions.
  39.  *       The values of the SQLState string as described in the XOPEN SQL spec.
  40.  *   <LI> An integer error code that is vendor specific.  Normally this will
  41.  *     be the actual error code returned by the underlying database.
  42.  *   <LI> A chain to a next Exception.  This can be used to provided additional
  43.  *      error information.
  44.  * </UL>
  45.  */
  46. public class SQLException extends java.lang.Exception {
  47.  
  48.     /**
  49.      * Construct a fully-specified SQLException  
  50.      *
  51.      * @param reason a description of the exception 
  52.      * @param SQLState an XOPEN code identifying the exception
  53.      * @param vendorCode a database vendor specific exception code
  54.      */
  55.     public SQLException(String reason, String SQLState, int vendorCode) {
  56.     super(reason);
  57.     this.SQLState = SQLState;
  58.     this.vendorCode = vendorCode;
  59.     if (!(this instanceof SQLWarning)) {
  60.         if (DriverManager.getLogStream() != null) {
  61.         DriverManager.println("SQLException: SQLState(" + SQLState + 
  62.                         ") vendor code(" + vendorCode + ")");
  63.         printStackTrace(DriverManager.getLogStream());
  64.         }
  65.     }
  66.     }
  67.  
  68.  
  69.     /**
  70.      * Construct an SQLException with a reason and SQLState;
  71.      * vendorCode defaults to 0.
  72.      *
  73.      * @param reason a description of the exception 
  74.      * @param SQLState an XOPEN code identifying the exception 
  75.      */
  76.     public SQLException(String reason, String SQLState) {
  77.     super(reason);
  78.     this.SQLState = SQLState;
  79.     this.vendorCode = 0;
  80.     if (!(this instanceof SQLWarning)) {
  81.         if (DriverManager.getLogStream() != null) {
  82.         printStackTrace(DriverManager.getLogStream());
  83.         DriverManager.println("SQLException: SQLState(" + SQLState + ")");
  84.         }
  85.     }
  86.     }
  87.  
  88.     /**
  89.      * Construct an SQLException with a reason; SQLState defaults to
  90.      * null and vendorCode defaults to 0.
  91.      *
  92.      * @param reason a description of the exception 
  93.      */
  94.     public SQLException(String reason) {
  95.     super(reason);
  96.     this.SQLState = null;
  97.     this.vendorCode = 0;
  98.     if (!(this instanceof SQLWarning)) {
  99.         if (DriverManager.getLogStream() != null) {
  100.         printStackTrace(DriverManager.getLogStream());
  101.         }
  102.     }
  103.     }
  104.  
  105.     /**
  106.      * Construct an SQLException; reason defaults to null, SQLState
  107.      * defaults to null and vendorCode defaults to 0.
  108.      * */
  109.     public SQLException() {
  110.     super();
  111.     this.SQLState = null;
  112.     this.vendorCode = 0;
  113.     if (!(this instanceof SQLWarning)) {
  114.         if (DriverManager.getLogStream() != null) {
  115.         printStackTrace(DriverManager.getLogStream());
  116.         }
  117.     }
  118.     }
  119.  
  120.     /**
  121.      * Get the SQLState
  122.      *
  123.      * @return the SQLState value
  124.      */
  125.     public String getSQLState() {
  126.     return (SQLState);
  127.     }    
  128.  
  129.     /**
  130.      * Get the vendor specific exception code
  131.      *
  132.      * @return the vendor's error code
  133.      */
  134.     public int getErrorCode() {
  135.     return (vendorCode);
  136.     }
  137.  
  138.     /**
  139.      * Get the exception chained to this one. 
  140.      *
  141.      * @return the next SQLException in the chain, null if none
  142.      */
  143.     public SQLException getNextException() {
  144.     return (next);
  145.     }
  146.  
  147.     /**
  148.      * Add an SQLException to the end of the chain.
  149.      *
  150.      * @param ex the new end of the SQLException chain
  151.      */
  152.     public synchronized void setNextException(SQLException ex) {
  153.     SQLException theEnd = this;
  154.     while (theEnd.next != null) {
  155.         theEnd = theEnd.next;
  156.     }
  157.     theEnd.next = ex;
  158.     }
  159.  
  160.     private String SQLState;
  161.     private int vendorCode;
  162.     private SQLException next;
  163. }
  164.