56380
|
1 |
/*
|
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
|
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 |
* <P>
|
|
29 |
* An exception that provides information on a database access error or other
|
|
30 |
* errors.
|
|
31 |
*
|
|
32 |
* <P>
|
|
33 |
* Each <code>SqlException</code> provides several kinds of information:
|
|
34 |
* <UL>
|
|
35 |
* <LI> a string describing the error. This is used as the Java Exception
|
|
36 |
* message, available via the method <code>getMesasge</code>.
|
|
37 |
* <LI> a "SQLstate" string, which follows either the XOPEN SQLstate conventions
|
|
38 |
* or the SQL:2003 conventions. The values of the SQLState string are described
|
|
39 |
* in the appropriate spec. The <code>DatabaseMetaData</code> method
|
|
40 |
* <code>getSQLStateType</code> can be used to discover whether the driver
|
|
41 |
* returns the XOPEN type or the SQL:2003 type.
|
|
42 |
* <LI> an integer error code that is specific to each vendor. Normally this
|
|
43 |
* will be the actual error code returned by the underlying database.
|
|
44 |
* <LI> the causal relationship, if any for this <code>SqlException</code>.
|
|
45 |
* <LI> the SQL string that was executing when the error occurred.
|
|
46 |
* <LI> the position in the SQL string where the error was detected.
|
|
47 |
* </UL>
|
|
48 |
*/
|
|
49 |
public class SqlException extends RuntimeException {
|
|
50 |
|
|
51 |
private static final long serialVersionUID = 1L;
|
|
52 |
|
|
53 |
// Fields
|
|
54 |
|
|
55 |
/**
|
|
56 |
*/
|
|
57 |
private String sqlState = null;
|
|
58 |
|
|
59 |
/**
|
|
60 |
*/
|
|
61 |
private int vendorCode = -1;
|
|
62 |
|
|
63 |
/**
|
|
64 |
* The SQL string that was sent to the database.
|
|
65 |
*/
|
|
66 |
private String sqlString = null;
|
|
67 |
|
|
68 |
/**
|
|
69 |
* The index of the first character in SQL where an error is detected. Zero
|
|
70 |
* based.
|
|
71 |
*/
|
|
72 |
private int position = -1;
|
|
73 |
|
|
74 |
// Constructors
|
|
75 |
|
|
76 |
private SqlException() {
|
|
77 |
super();
|
|
78 |
}
|
|
79 |
|
|
80 |
/**
|
|
81 |
*
|
|
82 |
* @param message
|
|
83 |
* @param cause
|
|
84 |
* @param sqlState
|
|
85 |
* @param vendorCode
|
|
86 |
* @param sql
|
|
87 |
* @param position
|
|
88 |
*/
|
|
89 |
public SqlException(String message, Throwable cause, String sqlState, int vendorCode, String sql, int position) {
|
|
90 |
super(message, cause);
|
|
91 |
this.sqlState = sqlState;
|
|
92 |
this.vendorCode = vendorCode;
|
|
93 |
this.sqlString = sql;
|
|
94 |
this.position = position;
|
|
95 |
}
|
|
96 |
|
|
97 |
// Methods
|
|
98 |
|
|
99 |
/**
|
|
100 |
* Retrieves the SqlState for this <code>SqlException</code> object.
|
|
101 |
*
|
|
102 |
* @return the SQLState value
|
|
103 |
*/
|
|
104 |
public String getSqlState() {
|
|
105 |
return (sqlState);
|
|
106 |
}
|
|
107 |
|
|
108 |
/**
|
|
109 |
* Retrieves the vendor-specific exception code for this
|
|
110 |
* <code>SqlException</code> object.
|
|
111 |
*
|
|
112 |
* @return the vendor's error code
|
|
113 |
*/
|
|
114 |
public int getVendorCode() {
|
|
115 |
return (vendorCode);
|
|
116 |
}
|
|
117 |
|
|
118 |
/**
|
|
119 |
* Get the position.
|
|
120 |
*
|
|
121 |
* @return the index of the first character in sql where an error is detected.
|
|
122 |
* Zero based.
|
|
123 |
*/
|
|
124 |
public int getPosition() {
|
|
125 |
return position;
|
|
126 |
}
|
|
127 |
|
|
128 |
/**
|
|
129 |
* Get the sql.
|
|
130 |
*
|
|
131 |
* @return the SQL string sent to the database
|
|
132 |
*/
|
|
133 |
public String getSqlString() {
|
|
134 |
return sqlString;
|
|
135 |
}
|
|
136 |
}
|