src/java.sql/share/classes/java/sql/SQLException.java
author psadhukhan
Fri, 09 Nov 2018 09:29:43 +0530
changeset 52543 3853631e6a07
parent 47216 71c04702a3d5
permissions -rw-r--r--
8213181: Updation of ProblemList.txt for removal of passing swing test Reviewed-by: serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
25976
4de01a56e3ee 8054555: javadoc cleanup for java.sql and javax.sql
lancea
parents: 23590
diff changeset
     2
 * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.sql;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.NoSuchElementException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * <P>An exception that provides information on a database access
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * error or other errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <P>Each <code>SQLException</code> provides several kinds of information:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *   <LI> a string describing the error.  This is used as the Java Exception
25976
4de01a56e3ee 8054555: javadoc cleanup for java.sql and javax.sql
lancea
parents: 23590
diff changeset
    39
 *       message, available via the method <code>getMessage</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *   <LI> a "SQLstate" string, which follows either the XOPEN SQLstate conventions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *        or the SQL:2003 conventions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *       The values of the SQLState string are described in the appropriate spec.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *       The <code>DatabaseMetaData</code> method <code>getSQLStateType</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *       can be used to discover whether the driver returns the XOPEN type or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *       the SQL:2003 type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *   <LI> an integer error code that is specific to each vendor.  Normally this will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *       be the actual error code returned by the underlying database.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *   <LI> a chain to a next Exception.  This can be used to provide additional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *       error information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *   <LI> the causal relationship, if any for this <code>SQLException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * </UL>
44256
12050b22e372 8176721: @since value errors java.sql module
mli
parents: 25991
diff changeset
    52
 *
12050b22e372 8176721: @since value errors java.sql module
mli
parents: 25991
diff changeset
    53
 * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
public class SQLException extends java.lang.Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                          implements Iterable<Throwable> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     *  Constructs a <code>SQLException</code> object with a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * <code>reason</code>, <code>SQLState</code>  and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * <code>vendorCode</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * The <code>cause</code> is not initialized, and may subsequently be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * initialized by a call to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * {@link Throwable#initCause(java.lang.Throwable)} method.
23590
ffd8b0b70511 8038493: Tidy warnings cleanup for java.sql
yan
parents: 23010
diff changeset
    66
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * @param reason a description of the exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * @param SQLState an XOPEN or SQL:2003 code identifying the exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * @param vendorCode a database vendor-specific exception code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public SQLException(String reason, String SQLState, int vendorCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        super(reason);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        this.SQLState = SQLState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        this.vendorCode = vendorCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        if (!(this instanceof SQLWarning)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            if (DriverManager.getLogWriter() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                DriverManager.println("SQLState(" + SQLState +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                                                ") vendor code(" + vendorCode + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                printStackTrace(DriverManager.getLogWriter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Constructs a <code>SQLException</code> object with a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * <code>reason</code> and <code>SQLState</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * The <code>cause</code> is not initialized, and may subsequently be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * initialized by a call to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * {@link Throwable#initCause(java.lang.Throwable)} method. The vendor code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * is initialized to 0.
23590
ffd8b0b70511 8038493: Tidy warnings cleanup for java.sql
yan
parents: 23010
diff changeset
    93
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @param reason a description of the exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @param SQLState an XOPEN or SQL:2003 code identifying the exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public SQLException(String reason, String SQLState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        super(reason);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        this.SQLState = SQLState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        this.vendorCode = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        if (!(this instanceof SQLWarning)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            if (DriverManager.getLogWriter() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                printStackTrace(DriverManager.getLogWriter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                DriverManager.println("SQLException: SQLState(" + SQLState + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *  Constructs a <code>SQLException</code> object with a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * <code>reason</code>. The  <code>SQLState</code>  is initialized to
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20880
diff changeset
   112
     * <code>null</code> and the vendor code is initialized to 0.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * The <code>cause</code> is not initialized, and may subsequently be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * initialized by a call to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * {@link Throwable#initCause(java.lang.Throwable)} method.
23590
ffd8b0b70511 8038493: Tidy warnings cleanup for java.sql
yan
parents: 23010
diff changeset
   117
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @param reason a description of the exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public SQLException(String reason) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        super(reason);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        this.SQLState = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        this.vendorCode = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        if (!(this instanceof SQLWarning)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            if (DriverManager.getLogWriter() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                printStackTrace(DriverManager.getLogWriter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Constructs a <code>SQLException</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * The <code>reason</code>, <code>SQLState</code> are initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * to <code>null</code> and the vendor code is initialized to 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * The <code>cause</code> is not initialized, and may subsequently be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * initialized by a call to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * {@link Throwable#initCause(java.lang.Throwable)} method.
20880
1b610151b316 8026812: doclint clean up for java.sql and javax.sql
lancea
parents: 5506
diff changeset
   139
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public SQLException() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        this.SQLState = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        this.vendorCode = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if (!(this instanceof SQLWarning)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            if (DriverManager.getLogWriter() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                printStackTrace(DriverManager.getLogWriter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *  Constructs a <code>SQLException</code> object with a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * <code>cause</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * The <code>SQLState</code> is initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * to <code>null</code> and the vendor code is initialized to 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * The <code>reason</code>  is initialized to <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * <code>cause==null</code> or to <code>cause.toString()</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * <code>cause!=null</code>.
23590
ffd8b0b70511 8038493: Tidy warnings cleanup for java.sql
yan
parents: 23010
diff changeset
   160
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param cause the underlying reason for this <code>SQLException</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * (which is saved for later retrieval by the <code>getCause()</code> method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * may be null indicating the cause is non-existent or unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public SQLException(Throwable cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        super(cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (!(this instanceof SQLWarning)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            if (DriverManager.getLogWriter() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                printStackTrace(DriverManager.getLogWriter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Constructs a <code>SQLException</code> object with a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * <code>reason</code> and  <code>cause</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * The <code>SQLState</code> is  initialized to <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * and the vendor code is initialized to 0.
23590
ffd8b0b70511 8038493: Tidy warnings cleanup for java.sql
yan
parents: 23010
diff changeset
   181
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @param reason a description of the exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @param cause the underlying reason for this <code>SQLException</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * (which is saved for later retrieval by the <code>getCause()</code> method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * may be null indicating the cause is non-existent or unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public SQLException(String reason, Throwable cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        super(reason,cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if (!(this instanceof SQLWarning)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            if (DriverManager.getLogWriter() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    printStackTrace(DriverManager.getLogWriter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Constructs a <code>SQLException</code> object with a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * <code>reason</code>, <code>SQLState</code> and  <code>cause</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * The vendor code is initialized to 0.
23590
ffd8b0b70511 8038493: Tidy warnings cleanup for java.sql
yan
parents: 23010
diff changeset
   202
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @param reason a description of the exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @param sqlState an XOPEN or SQL:2003 code identifying the exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @param cause the underlying reason for this <code>SQLException</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * (which is saved for later retrieval by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * <code>getCause()</code> method); may be null indicating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *     the cause is non-existent or unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public SQLException(String reason, String sqlState, Throwable cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        super(reason,cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        this.SQLState = sqlState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        this.vendorCode = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        if (!(this instanceof SQLWarning)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            if (DriverManager.getLogWriter() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                printStackTrace(DriverManager.getLogWriter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                DriverManager.println("SQLState(" + SQLState + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Constructs a <code>SQLException</code> object with a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * <code>reason</code>, <code>SQLState</code>, <code>vendorCode</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * and  <code>cause</code>.
23590
ffd8b0b70511 8038493: Tidy warnings cleanup for java.sql
yan
parents: 23010
diff changeset
   228
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @param reason a description of the exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @param sqlState an XOPEN or SQL:2003 code identifying the exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @param vendorCode a database vendor-specific exception code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @param cause the underlying reason for this <code>SQLException</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * (which is saved for later retrieval by the <code>getCause()</code> method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * may be null indicating the cause is non-existent or unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public SQLException(String reason, String sqlState, int vendorCode, Throwable cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        super(reason,cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        this.SQLState = sqlState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        this.vendorCode = vendorCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        if (!(this instanceof SQLWarning)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            if (DriverManager.getLogWriter() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                DriverManager.println("SQLState(" + SQLState +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                                                ") vendor code(" + vendorCode + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                printStackTrace(DriverManager.getLogWriter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * Retrieves the SQLState for this <code>SQLException</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @return the SQLState value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public String getSQLState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return (SQLState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * Retrieves the vendor-specific exception code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * for this <code>SQLException</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @return the vendor's error code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    public int getErrorCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        return (vendorCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Retrieves the exception chained to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * <code>SQLException</code> object by setNextException(SQLException ex).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @return the next <code>SQLException</code> object in the chain;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *         <code>null</code> if there are none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @see #setNextException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    public SQLException getNextException() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        return (next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * Adds an <code>SQLException</code> object to the end of the chain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @param ex the new exception that will be added to the end of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *            the <code>SQLException</code> chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @see #getNextException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public void setNextException(SQLException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        SQLException current = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        for(;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            SQLException next=current.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            if (next != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                current = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            if (nextUpdater.compareAndSet(current,null,ex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            current=current.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * Returns an iterator over the chained SQLExceptions.  The iterator will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * be used to iterate over each SQLException and its underlying cause
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * (if any).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @return an iterator over the chained SQLExceptions and causes in the proper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    public Iterator<Throwable> iterator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
       return new Iterator<Throwable>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
           SQLException firstException = SQLException.this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
           SQLException nextException = firstException.getNextException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
           Throwable cause = firstException.getCause();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
           public boolean hasNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
               if(firstException != null || nextException != null || cause != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                   return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
               return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
           public Throwable next() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
               Throwable throwable = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
               if(firstException != null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                   throwable = firstException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                   firstException = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
               else if(cause != null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                   throwable = cause;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                   cause = cause.getCause();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
               else if(nextException != null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                   throwable = nextException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                   cause = nextException.getCause();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                   nextException = nextException.getNextException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                   throw new NoSuchElementException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
               return throwable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
           public void remove() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
               throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
       };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    private String SQLState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    private int vendorCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    private volatile SQLException next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    private static final AtomicReferenceFieldUpdater<SQLException,SQLException> nextUpdater =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            AtomicReferenceFieldUpdater.newUpdater(SQLException.class,SQLException.class,"next");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    private static final long serialVersionUID = 2135244094396331484L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
}