Path: blob/master/src/java.sql/share/classes/java/sql/SQLWarning.java
41153 views
/*1* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.sql;2627/**28* <P>An exception that provides information on database access29* warnings. Warnings are silently chained to the object whose method30* caused it to be reported.31* <P>32* Warnings may be retrieved from {@code Connection}, {@code Statement},33* and {@code ResultSet} objects. Trying to retrieve a warning on a34* connection after it has been closed will cause an exception to be thrown.35* Similarly, trying to retrieve a warning on a statement after it has been36* closed or on a result set after it has been closed will cause37* an exception to be thrown. Note that closing a statement also38* closes a result set that it might have produced.39*40* @see Connection#getWarnings41* @see Statement#getWarnings42* @see ResultSet#getWarnings43* @since 1.144*/45public class SQLWarning extends SQLException {4647/**48* Constructs a {@code SQLWarning} object49* with a given {@code reason}, {@code SQLState} and50* {@code vendorCode}.51*52* The {@code cause} is not initialized, and may subsequently be53* initialized by a call to the54* {@link Throwable#initCause(java.lang.Throwable)} method.55*56* @param reason a description of the warning57* @param SQLState an XOPEN or SQL:2003 code identifying the warning58* @param vendorCode a database vendor-specific warning code59*/60public SQLWarning(String reason, String SQLState, int vendorCode) {61super(reason, SQLState, vendorCode);62DriverManager.println("SQLWarning: reason(" + reason +63") SQLState(" + SQLState +64") vendor code(" + vendorCode + ")");65}666768/**69* Constructs a {@code SQLWarning} object70* with a given {@code reason} and {@code SQLState}.71*72* The {@code cause} is not initialized, and may subsequently be73* initialized by a call to the74* {@link Throwable#initCause(java.lang.Throwable)} method. The vendor code75* is initialized to 0.76*77* @param reason a description of the warning78* @param SQLState an XOPEN or SQL:2003 code identifying the warning79*/80public SQLWarning(String reason, String SQLState) {81super(reason, SQLState);82DriverManager.println("SQLWarning: reason(" + reason +83") SQLState(" + SQLState + ")");84}8586/**87* Constructs a {@code SQLWarning} object88* with a given {@code reason}. The {@code SQLState}89* is initialized to {@code null} and the vendor code is initialized90* to 0.91*92* The {@code cause} is not initialized, and may subsequently be93* initialized by a call to the94* {@link Throwable#initCause(java.lang.Throwable)} method.95*96* @param reason a description of the warning97*/98public SQLWarning(String reason) {99super(reason);100DriverManager.println("SQLWarning: reason(" + reason + ")");101}102103/**104* Constructs a {@code SQLWarning} object.105* The {@code reason}, {@code SQLState} are initialized106* to {@code null} and the vendor code is initialized to 0.107*108* The {@code cause} is not initialized, and may subsequently be109* initialized by a call to the110* {@link Throwable#initCause(java.lang.Throwable)} method.111*112*/113public SQLWarning() {114super();115DriverManager.println("SQLWarning: ");116}117118/**119* Constructs a {@code SQLWarning} object120* with a given {@code cause}.121* The {@code SQLState} is initialized122* to {@code null} and the vendor code is initialized to 0.123* The {@code reason} is initialized to {@code null} if124* {@code cause==null} or to {@code cause.toString()} if125* {@code cause!=null}.126*127* @param cause the underlying reason for this {@code SQLWarning} (which is saved for later retrieval by the {@code getCause()} method); may be null indicating128* the cause is non-existent or unknown.129*/130public SQLWarning(Throwable cause) {131super(cause);132DriverManager.println("SQLWarning");133}134135/**136* Constructs a {@code SQLWarning} object137* with a given138* {@code reason} and {@code cause}.139* The {@code SQLState} is initialized to {@code null}140* and the vendor code is initialized to 0.141*142* @param reason a description of the warning143* @param cause the underlying reason for this {@code SQLWarning}144* (which is saved for later retrieval by the {@code getCause()} method);145* may be null indicating the cause is non-existent or unknown.146*/147public SQLWarning(String reason, Throwable cause) {148super(reason,cause);149DriverManager.println("SQLWarning : reason("+ reason + ")");150}151152/**153* Constructs a {@code SQLWarning} object154* with a given155* {@code reason}, {@code SQLState} and {@code cause}.156* The vendor code is initialized to 0.157*158* @param reason a description of the warning159* @param SQLState an XOPEN or SQL:2003 code identifying the warning160* @param cause the underlying reason for this {@code SQLWarning} (which is saved for later retrieval by the {@code getCause()} method); may be null indicating161* the cause is non-existent or unknown.162*/163public SQLWarning(String reason, String SQLState, Throwable cause) {164super(reason,SQLState,cause);165DriverManager.println("SQLWarning: reason(" + reason +166") SQLState(" + SQLState + ")");167}168169/**170* Constructs a{@code SQLWarning} object171* with a given172* {@code reason}, {@code SQLState}, {@code vendorCode}173* and {@code cause}.174*175* @param reason a description of the warning176* @param SQLState an XOPEN or SQL:2003 code identifying the warning177* @param vendorCode a database vendor-specific warning code178* @param cause the underlying reason for this {@code SQLWarning} (which is saved for later retrieval by the {@code getCause()} method); may be null indicating179* the cause is non-existent or unknown.180*/181public SQLWarning(String reason, String SQLState, int vendorCode, Throwable cause) {182super(reason,SQLState,vendorCode,cause);183DriverManager.println("SQLWarning: reason(" + reason +184") SQLState(" + SQLState +185") vendor code(" + vendorCode + ")");186187}188/**189* Retrieves the warning chained to this {@code SQLWarning} object by190* {@code setNextWarning}.191*192* @return the next {@code SQLException} in the chain; {@code null} if none193* @see #setNextWarning194*/195public SQLWarning getNextWarning() {196try {197return ((SQLWarning)getNextException());198} catch (ClassCastException ex) {199// The chained value isn't a SQLWarning.200// This is a programming error by whoever added it to201// the SQLWarning chain. We throw a Java "Error".202throw new Error("SQLWarning chain holds value that is not a SQLWarning");203}204}205206/**207* Adds a {@code SQLWarning} object to the end of the chain.208*209* @param w the new end of the {@code SQLException} chain210* @see #getNextWarning211*/212public void setNextWarning(SQLWarning w) {213setNextException(w);214}215216private static final long serialVersionUID = 3917336774604784856L;217}218219220