jdk/src/share/classes/java/sql/SQLWarning.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1996-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * <P>An exception that provides information on  database access
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * warnings. Warnings are silently chained to the object whose method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * caused it to be reported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * Warnings may be retrieved from <code>Connection</code>, <code>Statement</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * and <code>ResultSet</code> objects.  Trying to retrieve a warning on a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * connection after it has been closed will cause an exception to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Similarly, trying to retrieve a warning on a statement after it has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * closed or on a result set after it has been closed will cause
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * an exception to be thrown. Note that closing a statement also
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * closes a result set that it might have produced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @see Connection#getWarnings
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @see Statement#getWarnings
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @see ResultSet#getWarnings
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public class SQLWarning extends SQLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * Constructs a  <code>SQLWarning</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     *  with a given <code>reason</code>, <code>SQLState</code>  and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * <code>vendorCode</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * The <code>cause</code> is not initialized, and may subsequently be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * initialized by a call to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * {@link Throwable#initCause(java.lang.Throwable)} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * @param reason a description of the warning
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * @param SQLState an XOPEN or SQL:2003 code identifying the warning
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * @param vendorCode a database vendor-specific warning code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     public SQLWarning(String reason, String SQLState, int vendorCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        super(reason, SQLState, vendorCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        DriverManager.println("SQLWarning: reason(" + reason +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                              ") SQLState(" + SQLState +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                              ") vendor code(" + vendorCode + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Constructs a <code>SQLWarning</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * with a given <code>reason</code> and <code>SQLState</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * The <code>cause</code> is not initialized, and may subsequently be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * initialized by a call to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * {@link Throwable#initCause(java.lang.Throwable)} method. The vendor code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * is initialized to 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @param reason a description of the warning
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @param SQLState an XOPEN or SQL:2003 code identifying the warning
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public SQLWarning(String reason, String SQLState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        super(reason, SQLState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        DriverManager.println("SQLWarning: reason(" + reason +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                                  ") SQLState(" + SQLState + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Constructs a <code>SQLWarning</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * with a given <code>reason</code>. The <code>SQLState</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * is initialized to <code>null</code> and the vender code is initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * to 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * The <code>cause</code> is not initialized, and may subsequently be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * initialized by a call to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * {@link Throwable#initCause(java.lang.Throwable)} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @param reason a description of the warning
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public SQLWarning(String reason) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        super(reason);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        DriverManager.println("SQLWarning: reason(" + reason + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Constructs a  <code>SQLWarning</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * The <code>reason</code>, <code>SQLState</code> are initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * to <code>null</code> and the vendor code is initialized to 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * The <code>cause</code> is not initialized, and may subsequently be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * initialized by a call to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * {@link Throwable#initCause(java.lang.Throwable)} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public SQLWarning() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        DriverManager.println("SQLWarning: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * Constructs a <code>SQLWarning</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * with a given  <code>cause</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * The <code>SQLState</code> is initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * to <code>null</code> and the vendor code is initialized to 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * The <code>reason</code>  is initialized to <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <code>cause==null</code> or to <code>cause.toString()</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * <code>cause!=null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @param cause the underlying reason for this <code>SQLWarning</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *     the cause is non-existent or unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public SQLWarning(Throwable cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        super(cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        DriverManager.println("SQLWarning");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Constructs a <code>SQLWarning</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * with a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * <code>reason</code> and  <code>cause</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * The <code>SQLState</code> is  initialized to <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * and the vendor code is initialized to 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @param reason a description of the warning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @param cause  the underlying reason for this <code>SQLWarning</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * (which is saved for later retrieval by the <code>getCause()</code> method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * may be null indicating the cause is non-existent or unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public SQLWarning(String reason, Throwable cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        super(reason,cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        DriverManager.println("SQLWarning : reason("+ reason + ")");
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>SQLWarning</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * with a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * <code>reason</code>, <code>SQLState</code> and  <code>cause</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * The vendor code is initialized to 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @param reason a description of the warning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @param SQLState an XOPEN or SQL:2003 code identifying the warning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @param cause the underlying reason for this <code>SQLWarning</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *     the cause is non-existent or unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public SQLWarning(String reason, String SQLState, Throwable cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        super(reason,SQLState,cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        DriverManager.println("SQLWarning: reason(" + reason +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                                  ") SQLState(" + SQLState + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Constructs a<code>SQLWarning</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * with a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * <code>reason</code>, <code>SQLState</code>, <code>vendorCode</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * and  <code>cause</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @param reason a description of the warning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @param SQLState an XOPEN or SQL:2003 code identifying the warning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @param vendorCode a database vendor-specific warning code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @param cause the underlying reason for this <code>SQLWarning</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *     the cause is non-existent or unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public SQLWarning(String reason, String SQLState, int vendorCode, Throwable cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        super(reason,SQLState,vendorCode,cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        DriverManager.println("SQLWarning: reason(" + reason +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                              ") SQLState(" + SQLState +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                              ") vendor code(" + vendorCode + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * Retrieves the warning chained to this <code>SQLWarning</code> object by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * <code>setNextWarning</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @return the next <code>SQLException</code> in the chain; <code>null</code> if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @see #setNextWarning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public SQLWarning getNextWarning() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            return ((SQLWarning)getNextException());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        } catch (ClassCastException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            // The chained value isn't a SQLWarning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            // This is a programming error by whoever added it to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            // the SQLWarning chain.  We throw a Java "Error".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            throw new Error("SQLWarning chain holds value that is not a SQLWarning");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * Adds a <code>SQLWarning</code> object to the end of the chain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @param w the new end of the <code>SQLException</code> chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @see #getNextWarning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public void setNextWarning(SQLWarning w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        setNextException(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    private static final long serialVersionUID = 3917336774604784856L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
}