001: /**
002: * com.mckoi.database.jdbc.MSQLException 16 Aug 2000
003: *
004: * Mckoi SQL Database ( http://www.mckoi.com/database )
005: * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * Version 2 as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License Version 2 for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * Version 2 along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: * Change Log:
021: *
022: *
023: */package com.mckoi.database.jdbc;
024:
025: import java.sql.SQLException;
026: import java.io.*;
027:
028: /**
029: * SQLException used by the McKoi database engine.
030: *
031: * @author Tobias Downer
032: */
033:
034: public class MSQLException extends SQLException {
035:
036: private String server_error_msg;
037: private String server_stack_trace;
038:
039: public MSQLException(String reason, String SQLState, int vendorCode) {
040: super (reason, SQLState, vendorCode);
041: }
042:
043: public MSQLException(String reason, String SQLState) {
044: super (reason, SQLState);
045: }
046:
047: public MSQLException(String reason) {
048: super (reason);
049: }
050:
051: public MSQLException() {
052: super ();
053: }
054:
055: /**
056: * MSQL Specific. This stores the reason, the server exception message, and
057: * the server stack trace.
058: */
059: public MSQLException(String reason, String server_error_msg,
060: int vendor_code, Throwable server_error) {
061: super (reason, null, vendor_code);
062:
063: this .server_error_msg = server_error_msg;
064: if (server_error != null) {
065: StringWriter writer = new StringWriter();
066: server_error.printStackTrace(new PrintWriter(writer));
067: this .server_stack_trace = writer.toString();
068: } else {
069: this .server_stack_trace = "<< NO SERVER STACK TRACE >>";
070: }
071: }
072:
073: /**
074: * MSQL Specific. This stores the reason, the server exception message, and
075: * the server stack trace as a string.
076: */
077: public MSQLException(String reason, String server_error_msg,
078: int vendor_code, String server_error_trace) {
079: super (reason, null, vendor_code);
080:
081: this .server_error_msg = server_error_msg;
082: this .server_stack_trace = server_error_trace;
083: }
084:
085: /**
086: * Returns the error message that generated this exception.
087: */
088: public String getServerErrorMsg() {
089: return server_error_msg;
090: }
091:
092: /**
093: * Returns the server side stack trace for this error.
094: */
095: public String getServerErrorStackTrace() {
096: return server_stack_trace;
097: }
098:
099: /**
100: * Overwrites the print stack trace information with some more detailed
101: * information about the error.
102: */
103: public void printStackTrace() {
104: printStackTrace(System.err);
105: }
106:
107: /**
108: * Overwrites the print stack trace information with some more detailed
109: * information about the error.
110: */
111: public void printStackTrace(PrintStream s) {
112: synchronized (s) {
113: super .printStackTrace(s);
114: if (server_stack_trace != null) {
115: s.print("CAUSE: ");
116: s.println(server_stack_trace);
117: }
118: }
119: }
120:
121: /**
122: * Overwrites the print stack trace information with some more detailed
123: * information about the error.
124: */
125: public void printStackTrace(PrintWriter s) {
126: synchronized (s) {
127: super .printStackTrace(s);
128: if (server_stack_trace != null) {
129: s.print("CAUSE: ");
130: s.println(server_stack_trace);
131: }
132: }
133: }
134:
135: /**
136: * Returns an SQLException that is used for all unsupported features of the
137: * JDBC driver.
138: */
139: public static SQLException unsupported() {
140: return new MSQLException("Not Supported");
141: }
142:
143: }
|