jdk/src/java.sql/share/classes/java/sql/SQLException.java
author chegar
Mon, 18 Aug 2014 10:59:36 +0100
changeset 25991 e48157b42439
parent 25976 jdk/src/share/classes/java/sql/SQLException.java@4de01a56e3ee
parent 25859 jdk/src/share/classes/java/sql/SQLException.java@3317bb8137f4
child 44256 12050b22e372
permissions -rw-r--r--
Merge
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>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
public class SQLException extends java.lang.Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                          implements Iterable<Throwable> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     *  Constructs a <code>SQLException</code> object with a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * <code>reason</code>, <code>SQLState</code>  and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * <code>vendorCode</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * The <code>cause</code> is not initialized, and may subsequently be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * initialized by a call to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * {@link Throwable#initCause(java.lang.Throwable)} method.
23590
ffd8b0b70511 8038493: Tidy warnings cleanup for java.sql
yan
parents: 23010
diff changeset
    64
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * @param reason a description of the exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * @param SQLState an XOPEN or SQL:2003 code identifying the exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * @param vendorCode a database vendor-specific exception code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public SQLException(String reason, String SQLState, int vendorCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        super(reason);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        this.SQLState = SQLState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        this.vendorCode = vendorCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        if (!(this instanceof SQLWarning)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            if (DriverManager.getLogWriter() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                DriverManager.println("SQLState(" + SQLState +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                                                ") vendor code(" + vendorCode + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                printStackTrace(DriverManager.getLogWriter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
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
     * Constructs a <code>SQLException</code> object with a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * <code>reason</code> and <code>SQLState</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * The <code>cause</code> is not initialized, and may subsequently be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * initialized by a call to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * {@link Throwable#initCause(java.lang.Throwable)} method. The vendor code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * is initialized to 0.
23590
ffd8b0b70511 8038493: Tidy warnings cleanup for java.sql
yan
parents: 23010
diff changeset
    91
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param reason a description of the exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @param SQLState an XOPEN or SQL:2003 code identifying the exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public SQLException(String reason, String SQLState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        super(reason);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        this.SQLState = SQLState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        this.vendorCode = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        if (!(this instanceof SQLWarning)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            if (DriverManager.getLogWriter() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                printStackTrace(DriverManager.getLogWriter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                DriverManager.println("SQLException: SQLState(" + SQLState + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
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
     *  Constructs a <code>SQLException</code> object with a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * <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
   110
     * <code>null</code> and the vendor code is initialized to 0.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * The <code>cause</code> is not initialized, and may subsequently be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * initialized by a call to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * {@link Throwable#initCause(java.lang.Throwable)} method.
23590
ffd8b0b70511 8038493: Tidy warnings cleanup for java.sql
yan
parents: 23010
diff changeset
   115
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @param reason a description of the exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public SQLException(String reason) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        super(reason);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        this.SQLState = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        this.vendorCode = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        if (!(this instanceof SQLWarning)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            if (DriverManager.getLogWriter() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                printStackTrace(DriverManager.getLogWriter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
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
     * Constructs a <code>SQLException</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * The <code>reason</code>, <code>SQLState</code> are initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * to <code>null</code> and the vendor code is initialized to 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * The <code>cause</code> is not initialized, and may subsequently be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * initialized by a call to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * {@link Throwable#initCause(java.lang.Throwable)} method.
20880
1b610151b316 8026812: doclint clean up for java.sql and javax.sql
lancea
parents: 5506
diff changeset
   137
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public SQLException() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        this.SQLState = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        this.vendorCode = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        if (!(this instanceof SQLWarning)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            if (DriverManager.getLogWriter() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                printStackTrace(DriverManager.getLogWriter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
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
     *  Constructs a <code>SQLException</code> object with a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * <code>cause</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * The <code>SQLState</code> is initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * to <code>null</code> and the vendor code is initialized to 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * The <code>reason</code>  is initialized to <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * <code>cause==null</code> or to <code>cause.toString()</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * <code>cause!=null</code>.
23590
ffd8b0b70511 8038493: Tidy warnings cleanup for java.sql
yan
parents: 23010
diff changeset
   158
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @param cause the underlying reason for this <code>SQLException</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * (which is saved for later retrieval by the <code>getCause()</code> method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * may be null indicating the cause is non-existent or unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public SQLException(Throwable cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        super(cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (!(this instanceof SQLWarning)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            if (DriverManager.getLogWriter() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                printStackTrace(DriverManager.getLogWriter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
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
     * Constructs a <code>SQLException</code> object with a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * <code>reason</code> and  <code>cause</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * The <code>SQLState</code> is  initialized to <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * and the vendor code is initialized to 0.
23590
ffd8b0b70511 8038493: Tidy warnings cleanup for java.sql
yan
parents: 23010
diff changeset
   179
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param reason a description of the exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @param cause the underlying reason for this <code>SQLException</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * (which is saved for later retrieval by the <code>getCause()</code> method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * may be null indicating the cause is non-existent or unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public SQLException(String reason, Throwable cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        super(reason,cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if (!(this instanceof SQLWarning)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            if (DriverManager.getLogWriter() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                    printStackTrace(DriverManager.getLogWriter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
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
     * Constructs a <code>SQLException</code> object with a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * <code>reason</code>, <code>SQLState</code> and  <code>cause</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * The vendor code is initialized to 0.
23590
ffd8b0b70511 8038493: Tidy warnings cleanup for java.sql
yan
parents: 23010
diff changeset
   200
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @param reason a description of the exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @param sqlState an XOPEN or SQL:2003 code identifying the exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @param cause the underlying reason for this <code>SQLException</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * (which is saved for later retrieval by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * <code>getCause()</code> method); may be null indicating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *     the cause is non-existent or unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public SQLException(String reason, String sqlState, Throwable cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        super(reason,cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        this.SQLState = sqlState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        this.vendorCode = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (!(this instanceof SQLWarning)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            if (DriverManager.getLogWriter() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                printStackTrace(DriverManager.getLogWriter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                DriverManager.println("SQLState(" + SQLState + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
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
     * Constructs a <code>SQLException</code> object with a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * <code>reason</code>, <code>SQLState</code>, <code>vendorCode</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * and  <code>cause</code>.
23590
ffd8b0b70511 8038493: Tidy warnings cleanup for java.sql
yan
parents: 23010
diff changeset
   226
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @param reason a description of the exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @param sqlState an XOPEN or SQL:2003 code identifying the exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @param vendorCode a database vendor-specific exception code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @param cause the underlying reason for this <code>SQLException</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * (which is saved for later retrieval by the <code>getCause()</code> method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * may be null indicating the cause is non-existent or unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public SQLException(String reason, String sqlState, int vendorCode, Throwable cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        super(reason,cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        this.SQLState = sqlState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        this.vendorCode = vendorCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (!(this instanceof SQLWarning)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            if (DriverManager.getLogWriter() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                DriverManager.println("SQLState(" + SQLState +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                                                ") vendor code(" + vendorCode + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                printStackTrace(DriverManager.getLogWriter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
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
     * Retrieves the SQLState for this <code>SQLException</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @return the SQLState value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public String getSQLState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        return (SQLState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * Retrieves the vendor-specific exception code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * for this <code>SQLException</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @return the vendor's error code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public int getErrorCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        return (vendorCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Retrieves the exception chained to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * <code>SQLException</code> object by setNextException(SQLException ex).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @return the next <code>SQLException</code> object in the chain;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *         <code>null</code> if there are none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @see #setNextException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    public SQLException getNextException() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        return (next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * Adds an <code>SQLException</code> object to the end of the chain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @param ex the new exception that will be added to the end of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *            the <code>SQLException</code> chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @see #getNextException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    public void setNextException(SQLException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        SQLException current = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        for(;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            SQLException next=current.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            if (next != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                current = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            if (nextUpdater.compareAndSet(current,null,ex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            current=current.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * Returns an iterator over the chained SQLExceptions.  The iterator will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * be used to iterate over each SQLException and its underlying cause
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * (if any).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @return an iterator over the chained SQLExceptions and causes in the proper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public Iterator<Throwable> iterator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
       return new Iterator<Throwable>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
           SQLException firstException = SQLException.this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
           SQLException nextException = firstException.getNextException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
           Throwable cause = firstException.getCause();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
           public boolean hasNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
               if(firstException != null || nextException != null || cause != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                   return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
               return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
           public Throwable next() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
               Throwable throwable = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
               if(firstException != null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                   throwable = firstException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                   firstException = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
               else if(cause != null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                   throwable = cause;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                   cause = cause.getCause();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
               else if(nextException != null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                   throwable = nextException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                   cause = nextException.getCause();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                   nextException = nextException.getNextException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
               else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                   throw new NoSuchElementException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
               return throwable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
           public void remove() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
               throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
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
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    private String SQLState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    private int vendorCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    private volatile SQLException next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    private static final AtomicReferenceFieldUpdater<SQLException,SQLException> nextUpdater =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            AtomicReferenceFieldUpdater.newUpdater(SQLException.class,SQLException.class,"next");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    private static final long serialVersionUID = 2135244094396331484L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
}