KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > sql > SQLWarning


1 /*
2  * @(#)SQLWarning.java 1.25 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.sql;
9
10 /**
11  * <P>An exception that provides information on database access
12  * warnings. Warnings are silently chained to the object whose method
13  * caused it to be reported.
14  * <P>
15  * Warnings may be retrieved from <code>Connection</code>, <code>Statement</code>,
16  * and <code>ResultSet</code> objects. Trying to retrieve a warning on a
17  * connection after it has been closed will cause an exception to be thrown.
18  * Similarly, trying to retrieve a warning on a statement after it has been
19  * closed or on a result set after it has been closed will cause
20  * an exception to be thrown. Note that closing a statement also
21  * closes a result set that it might have produced.
22  *
23  * @see Connection#getWarnings
24  * @see Statement#getWarnings
25  * @see ResultSet#getWarnings
26  */

27 public class SQLWarning extends SQLException JavaDoc {
28
29     /**
30      * Constructs a fully-specified <code>SQLWarning</code> object
31      * initialized with the given values.
32      *
33      * @param reason a description of the warning
34      * @param SQLstate an XOPEN code identifying the warning
35      * @param vendorCode a database vendor-specific warning code
36      */

37      public SQLWarning(String JavaDoc reason, String JavaDoc SQLstate, int vendorCode) {
38     super(reason, SQLstate, vendorCode);
39     DriverManager.println("SQLWarning: reason(" + reason +
40                   ") SQLstate(" + SQLstate +
41                   ") vendor code(" + vendorCode + ")");
42     }
43
44
45     /**
46      * Constructs an <code>SQLWarning</code> object
47      * with the given reason and SQLState;
48      * the vendorCode defaults to 0.
49      *
50      * @param reason a description of the warning
51      * @param SQLstate an XOPEN code identifying the warning
52      */

53     public SQLWarning(String JavaDoc reason, String JavaDoc SQLstate) {
54     super(reason, SQLstate);
55     DriverManager.println("SQLWarning: reason(" + reason +
56                   ") SQLState(" + SQLstate + ")");
57     }
58
59     /**
60      * Constructs an <code>SQLWarning</code> object
61      * with the given value for a reason; SQLstate defaults to
62      * <code>null</code>, and vendorCode defaults to 0.
63      *
64      * @param reason a description of the warning
65      */

66     public SQLWarning(String JavaDoc reason) {
67     super(reason);
68     DriverManager.println("SQLWarning: reason(" + reason + ")");
69     }
70
71     /**
72      * Constructs a default <code>SQLWarning</code> object.
73      * The reason defaults to <code>null</code>, SQLState
74      * defaults to <code>null</code>, and vendorCode defaults to 0.
75      *
76      */

77     public SQLWarning() {
78     super();
79     DriverManager.println("SQLWarning: ");
80     }
81
82
83     /**
84      * Retrieves the warning chained to this <code>SQLWarning</code> object.
85      *
86      * @return the next <code>SQLException</code> in the chain; <code>null</code> if none
87      * @see #setNextWarning
88      */

89     public SQLWarning JavaDoc getNextWarning() {
90     try {
91         return ((SQLWarning JavaDoc)getNextException());
92     } catch (ClassCastException JavaDoc ex) {
93         // The chained value isn't a SQLWarning.
94
// This is a programming error by whoever added it to
95
// the SQLWarning chain. We throw a Java "Error".
96
throw new Error JavaDoc("SQLWarning chain holds value that is not a SQLWarning");
97     }
98     }
99
100     /**
101      * Adds an <code>SQLWarning</code> object to the end of the chain.
102      *
103      * @param w the new end of the <code>SQLException</code> chain
104      * @see #getNextWarning
105      */

106     public void setNextWarning(SQLWarning JavaDoc w) {
107     setNextException(w);
108     }
109
110 }
111
Popular Tags