56380
|
1 |
/*
|
56475
|
2 |
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
|
56380
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
|
24 |
*/
|
|
25 |
package jdk.incubator.sql2;
|
|
26 |
|
|
27 |
/**
|
|
28 |
* An exception that provides information on a database access error or other
|
|
29 |
* errors.
|
|
30 |
*
|
|
31 |
* <P>
|
56997
|
32 |
* Each {@code SqlException} provides several kinds of information:
|
56380
|
33 |
* <UL>
|
|
34 |
* <LI> a string describing the error. This is used as the Java Exception
|
56997
|
35 |
* message, available via the method {@link getMessage}.
|
56380
|
36 |
* <LI> a "SQLstate" string, which follows either the XOPEN SQLstate conventions
|
|
37 |
* or the SQL:2003 conventions. The values of the SQLState string are described
|
56997
|
38 |
* in the appropriate spec.
|
56380
|
39 |
* <LI> an integer error code that is specific to each vendor. Normally this
|
|
40 |
* will be the actual error code returned by the underlying database.
|
56997
|
41 |
* <LI> the causal relationship, if any for this {@code SqlException}.
|
|
42 |
* <LI> the SQL string that was executing when the error occurred. May be {@code null}.
|
56380
|
43 |
* <LI> the position in the SQL string where the error was detected.
|
|
44 |
* </UL>
|
|
45 |
*/
|
|
46 |
public class SqlException extends RuntimeException {
|
|
47 |
|
|
48 |
private static final long serialVersionUID = 1L;
|
|
49 |
|
|
50 |
// Fields
|
|
51 |
|
|
52 |
/**
|
|
53 |
*/
|
56475
|
54 |
private final String sqlState;
|
56380
|
55 |
|
|
56 |
/**
|
|
57 |
*/
|
56475
|
58 |
private final int vendorCode;
|
56380
|
59 |
|
|
60 |
/**
|
|
61 |
* The SQL string that was sent to the database.
|
|
62 |
*/
|
56475
|
63 |
private final String sqlString;
|
56380
|
64 |
|
|
65 |
/**
|
|
66 |
* The index of the first character in SQL where an error is detected. Zero
|
|
67 |
* based.
|
|
68 |
*/
|
56475
|
69 |
private final int position;
|
56380
|
70 |
|
|
71 |
// Constructors
|
56797
|
72 |
|
|
73 |
public SqlException(Throwable ex) {
|
|
74 |
super(ex);
|
|
75 |
this.sqlState = null;
|
|
76 |
this.vendorCode = -1;
|
|
77 |
this.sqlString = null;
|
|
78 |
this.position = -1;
|
|
79 |
}
|
56380
|
80 |
|
|
81 |
/**
|
|
82 |
*
|
56475
|
83 |
* @param message
|
|
84 |
* @param cause
|
|
85 |
* @param sqlState
|
|
86 |
* @param vendorCode
|
|
87 |
* @param sql
|
|
88 |
* @param position
|
56380
|
89 |
*/
|
|
90 |
public SqlException(String message, Throwable cause, String sqlState, int vendorCode, String sql, int position) {
|
|
91 |
super(message, cause);
|
|
92 |
this.sqlState = sqlState;
|
|
93 |
this.vendorCode = vendorCode;
|
|
94 |
this.sqlString = sql;
|
|
95 |
this.position = position;
|
|
96 |
}
|
|
97 |
|
|
98 |
// Methods
|
|
99 |
|
|
100 |
/**
|
56997
|
101 |
* Retrieves the SqlState for this {@code SqlException} object.
|
56380
|
102 |
*
|
|
103 |
* @return the SQLState value
|
|
104 |
*/
|
|
105 |
public String getSqlState() {
|
|
106 |
return (sqlState);
|
|
107 |
}
|
|
108 |
|
|
109 |
/**
|
|
110 |
* Retrieves the vendor-specific exception code for this
|
56997
|
111 |
* {@code SqlException} object.
|
56380
|
112 |
*
|
|
113 |
* @return the vendor's error code
|
|
114 |
*/
|
|
115 |
public int getVendorCode() {
|
|
116 |
return (vendorCode);
|
|
117 |
}
|
|
118 |
|
|
119 |
/**
|
|
120 |
* Get the position.
|
|
121 |
*
|
|
122 |
* @return the index of the first character in sql where an error is detected.
|
56997
|
123 |
* Zero based. {@code -1} if the position is not defined or unknown.
|
56380
|
124 |
*/
|
|
125 |
public int getPosition() {
|
|
126 |
return position;
|
|
127 |
}
|
|
128 |
|
|
129 |
/**
|
|
130 |
* Get the sql.
|
|
131 |
*
|
56997
|
132 |
* @return the SQL string sent to the database. May be {@code null}.
|
56380
|
133 |
*/
|
|
134 |
public String getSqlString() {
|
|
135 |
return sqlString;
|
|
136 |
}
|
|
137 |
}
|