1 24 25 package com.mckoi.database.jdbc; 26 27 import java.sql.SQLException ; 28 import java.io.*; 29 30 35 36 public class MSQLException extends SQLException { 37 38 private String server_error_msg; 39 private String server_stack_trace; 40 41 42 43 public MSQLException(String reason, String SQLState, int vendorCode) { 44 super(reason, SQLState, vendorCode); 45 } 46 47 public MSQLException(String reason, String SQLState) { 48 super(reason, SQLState); 49 } 50 51 public MSQLException(String reason) { 52 super(reason); 53 } 54 55 public MSQLException() { 56 super(); 57 } 58 59 63 public MSQLException(String reason, String server_error_msg, int vendor_code, 64 Throwable 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 82 public MSQLException(String reason, String server_error_msg, int vendor_code, 83 String 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 93 public String getServerErrorMsg() { 94 return server_error_msg; 95 } 96 97 100 public String getServerErrorStackTrace() { 101 return server_stack_trace; 102 } 103 104 108 public void printStackTrace() { 109 printStackTrace(System.err); 110 } 111 112 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 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 144 public static SQLException unsupported() { 145 return new MSQLException("Not Supported"); 146 } 147 148 } 149 | Popular Tags |