Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/sql/SQLWarning.java
38829 views
/*1* Copyright (c) 1996, 2013, 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>, <code>Statement</code>,33* and <code>ResultSet</code> 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*/44public class SQLWarning extends SQLException {4546/**47* Constructs a <code>SQLWarning</code> object48* with a given <code>reason</code>, <code>SQLState</code> and49* <code>vendorCode</code>.50*51* The <code>cause</code> is not initialized, and may subsequently be52* initialized by a call to the53* {@link Throwable#initCause(java.lang.Throwable)} method.54* <p>55* @param reason a description of the warning56* @param SQLState an XOPEN or SQL:2003 code identifying the warning57* @param vendorCode a database vendor-specific warning code58*/59public SQLWarning(String reason, String SQLState, int vendorCode) {60super(reason, SQLState, vendorCode);61DriverManager.println("SQLWarning: reason(" + reason +62") SQLState(" + SQLState +63") vendor code(" + vendorCode + ")");64}656667/**68* Constructs a <code>SQLWarning</code> object69* with a given <code>reason</code> and <code>SQLState</code>.70*71* The <code>cause</code> is not initialized, and may subsequently be72* initialized by a call to the73* {@link Throwable#initCause(java.lang.Throwable)} method. The vendor code74* is initialized to 0.75* <p>76* @param reason a description of the warning77* @param SQLState an XOPEN or SQL:2003 code identifying the warning78*/79public SQLWarning(String reason, String SQLState) {80super(reason, SQLState);81DriverManager.println("SQLWarning: reason(" + reason +82") SQLState(" + SQLState + ")");83}8485/**86* Constructs a <code>SQLWarning</code> object87* with a given <code>reason</code>. The <code>SQLState</code>88* is initialized to <code>null</code> and the vendor code is initialized89* to 0.90*91* The <code>cause</code> is not initialized, and may subsequently be92* initialized by a call to the93* {@link Throwable#initCause(java.lang.Throwable)} method.94* <p>95* @param reason a description of the warning96*/97public SQLWarning(String reason) {98super(reason);99DriverManager.println("SQLWarning: reason(" + reason + ")");100}101102/**103* Constructs a <code>SQLWarning</code> object.104* The <code>reason</code>, <code>SQLState</code> are initialized105* to <code>null</code> and the vendor code is initialized to 0.106*107* The <code>cause</code> is not initialized, and may subsequently be108* initialized by a call to the109* {@link Throwable#initCause(java.lang.Throwable)} method.110*111*/112public SQLWarning() {113super();114DriverManager.println("SQLWarning: ");115}116117/**118* Constructs a <code>SQLWarning</code> object119* with a given <code>cause</code>.120* The <code>SQLState</code> is initialized121* to <code>null</code> and the vendor code is initialized to 0.122* The <code>reason</code> is initialized to <code>null</code> if123* <code>cause==null</code> or to <code>cause.toString()</code> if124* <code>cause!=null</code>.125* <p>126* @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 indicating127* the cause is non-existent or unknown.128*/129public SQLWarning(Throwable cause) {130super(cause);131DriverManager.println("SQLWarning");132}133134/**135* Constructs a <code>SQLWarning</code> object136* with a given137* <code>reason</code> and <code>cause</code>.138* The <code>SQLState</code> is initialized to <code>null</code>139* and the vendor code is initialized to 0.140* <p>141* @param reason a description of the warning142* @param cause the underlying reason for this <code>SQLWarning</code>143* (which is saved for later retrieval by the <code>getCause()</code> method);144* may be null indicating the cause is non-existent or unknown.145*/146public SQLWarning(String reason, Throwable cause) {147super(reason,cause);148DriverManager.println("SQLWarning : reason("+ reason + ")");149}150151/**152* Constructs a <code>SQLWarning</code> object153* with a given154* <code>reason</code>, <code>SQLState</code> and <code>cause</code>.155* The vendor code is initialized to 0.156* <p>157* @param reason a description of the warning158* @param SQLState an XOPEN or SQL:2003 code identifying the warning159* @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 indicating160* the cause is non-existent or unknown.161*/162public SQLWarning(String reason, String SQLState, Throwable cause) {163super(reason,SQLState,cause);164DriverManager.println("SQLWarning: reason(" + reason +165") SQLState(" + SQLState + ")");166}167168/**169* Constructs a<code>SQLWarning</code> object170* with a given171* <code>reason</code>, <code>SQLState</code>, <code>vendorCode</code>172* and <code>cause</code>.173* <p>174* @param reason a description of the warning175* @param SQLState an XOPEN or SQL:2003 code identifying the warning176* @param vendorCode a database vendor-specific warning code177* @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 indicating178* the cause is non-existent or unknown.179*/180public SQLWarning(String reason, String SQLState, int vendorCode, Throwable cause) {181super(reason,SQLState,vendorCode,cause);182DriverManager.println("SQLWarning: reason(" + reason +183") SQLState(" + SQLState +184") vendor code(" + vendorCode + ")");185186}187/**188* Retrieves the warning chained to this <code>SQLWarning</code> object by189* <code>setNextWarning</code>.190*191* @return the next <code>SQLException</code> in the chain; <code>null</code> if none192* @see #setNextWarning193*/194public SQLWarning getNextWarning() {195try {196return ((SQLWarning)getNextException());197} catch (ClassCastException ex) {198// The chained value isn't a SQLWarning.199// This is a programming error by whoever added it to200// the SQLWarning chain. We throw a Java "Error".201throw new Error("SQLWarning chain holds value that is not a SQLWarning");202}203}204205/**206* Adds a <code>SQLWarning</code> object to the end of the chain.207*208* @param w the new end of the <code>SQLException</code> chain209* @see #getNextWarning210*/211public void setNextWarning(SQLWarning w) {212setNextException(w);213}214215private static final long serialVersionUID = 3917336774604784856L;216}217218219