KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mckoi > database > jdbc > MSQLException


1 /**
2  * com.mckoi.database.jdbc.MSQLException 16 Aug 2000
3  *
4  * Mckoi SQL Database ( http://www.mckoi.com/database )
5  * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * Version 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License Version 2 for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * Version 2 along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  * Change Log:
21  *
22  *
23  */

24
25 package com.mckoi.database.jdbc;
26
27 import java.sql.SQLException JavaDoc;
28 import java.io.*;
29
30 /**
31  * SQLException used by the McKoi database engine.
32  *
33  * @author Tobias Downer
34  */

35
36 public class MSQLException extends SQLException JavaDoc {
37
38   private String JavaDoc server_error_msg;
39   private String JavaDoc server_stack_trace;
40
41
42
43   public MSQLException(String JavaDoc reason, String JavaDoc SQLState, int vendorCode) {
44     super(reason, SQLState, vendorCode);
45   }
46
47   public MSQLException(String JavaDoc reason, String JavaDoc SQLState) {
48     super(reason, SQLState);
49   }
50
51   public MSQLException(String JavaDoc reason) {
52     super(reason);
53   }
54
55   public MSQLException() {
56     super();
57   }
58
59   /**
60    * MSQL Specific. This stores the reason, the server exception message, and
61    * the server stack trace.
62    */

63   public MSQLException(String JavaDoc reason, String JavaDoc server_error_msg, int vendor_code,
64                        Throwable JavaDoc server_error) {
65     super(reason, null, vendor_code);
66
67     this.server_error_msg = server_error_msg;
68     if (server_error != null) {
69       StringWriter writer = new StringWriter();
70       server_error.printStackTrace(new PrintWriter(writer));
71       this.server_stack_trace = writer.toString();
72     }
73     else {
74       this.server_stack_trace = "<< NO SERVER STACK TRACE >>";
75     }
76   }
77
78   /**
79    * MSQL Specific. This stores the reason, the server exception message, and
80    * the server stack trace as a string.
81    */

82   public MSQLException(String JavaDoc reason, String JavaDoc server_error_msg, int vendor_code,
83                        String JavaDoc server_error_trace) {
84     super(reason, null, vendor_code);
85
86     this.server_error_msg = server_error_msg;
87     this.server_stack_trace = server_error_trace;
88   }
89
90   /**
91    * Returns the error message that generated this exception.
92    */

93   public String JavaDoc getServerErrorMsg() {
94     return server_error_msg;
95   }
96
97   /**
98    * Returns the server side stack trace for this error.
99    */

100   public String JavaDoc getServerErrorStackTrace() {
101     return server_stack_trace;
102   }
103
104   /**
105    * Overwrites the print stack trace information with some more detailed
106    * information about the error.
107    */

108   public void printStackTrace() {
109     printStackTrace(System.err);
110   }
111
112   /**
113    * Overwrites the print stack trace information with some more detailed
114    * information about the error.
115    */

116   public void printStackTrace(PrintStream s) {
117     synchronized(s) {
118       super.printStackTrace(s);
119       if (server_stack_trace != null) {
120         s.print("CAUSE: ");
121         s.println(server_stack_trace);
122       }
123     }
124   }
125
126   /**
127    * Overwrites the print stack trace information with some more detailed
128    * information about the error.
129    */

130   public void printStackTrace(PrintWriter s) {
131     synchronized(s) {
132       super.printStackTrace(s);
133       if (server_stack_trace != null) {
134         s.print("CAUSE: ");
135         s.println(server_stack_trace);
136       }
137     }
138   }
139
140   /**
141    * Returns an SQLException that is used for all unsupported features of the
142    * JDBC driver.
143    */

144   public static SQLException JavaDoc unsupported() {
145     return new MSQLException("Not Supported");
146   }
147   
148 }
149
Popular Tags