1 21 22 package org.apache.derbyTesting.functionTests.util; 23 24 import java.io.PrintStream ; 25 import java.io.PrintWriter ; 26 import java.io.File ; 27 import java.io.FileNotFoundException ; 28 import java.io.IOException ; 29 30 import java.sql.Connection ; 31 import java.sql.DriverManager ; 32 import java.sql.SQLException ; 33 import java.sql.SQLWarning ; 34 import java.sql.Statement ; 35 import java.sql.PreparedStatement ; 36 import java.sql.ResultSet ; 37 import java.sql.ResultSetMetaData ; 38 import java.sql.Types ; 39 40 import java.util.Properties ; 41 import java.util.Enumeration ; 42 import java.util.Vector ; 43 44 45 import org.apache.derby.impl.tools.ij.ijException; 46 47 import org.apache.derby.tools.JDBCDisplayUtil; 48 49 52 53 public class JDBCTestDisplayUtil extends JDBCDisplayUtil { 54 55 60 61 static public void ShowCommonSQLException(PrintStream out, Throwable e) { 62 if (e == null) return; 63 64 if (e instanceof SQLException ) 65 { 66 SQLException se = (SQLException )e; 67 if (isDataConversionException(se)) 68 out.println ("Data Conversion SQLException"); 69 else if (isResultSetClosedException(se)) 70 out.println("Result Set Closed Exception"); 71 else if (isNullSQLStringException(se)) 72 out.println("Null SQL String Exception"); 73 else if (isInvalidParameterException(se)) 74 out.println("Invalid Parameter SQL Exception"); 75 else if (isValidOnScrollCursorsException(se)) 76 out.println("Method Only Valid On Scroll Cursors SQL Exception"); 77 else if (isInvalidMethodReturnException(se)) 78 out.println("Invalid Method Returning a ResultSet or Row Count SQL Exception"); 79 else if (isTableDoesNotExistException(se)) 80 out.println("Table Does Not Exist SQL Exception"); 81 else if (isReturnsInvalidResultSetException(se)) 82 out.println("Invalid Method Returning ResultSet SQL Exception"); 83 else 84 ShowSQLException(out, se); 85 } 86 else 87 ShowException(out, e); 88 } 89 90 static private boolean isDataConversionException(SQLException se) 91 { 92 if ((se.getMessage() != null && 93 se.getMessage().indexOf("Invalid data conversion") >= 0) 94 || (se.getSQLState() != null && 95 (se.getSQLState().equals("22018") 96 || se.getSQLState().equals("22005") 97 || se.getSQLState().equals("22007")))) 98 return true; 99 return false; 100 } 101 102 static private boolean isResultSetClosedException(SQLException se) 103 { 104 if ((se.getMessage() != null && 105 se.getMessage().indexOf("Invalid operation: result set closed") >= 0) 106 || (se.getSQLState() != null && 107 (se.getSQLState().equals("XCL16")))) 108 return true; 109 return false; 110 } 111 112 static private boolean isNullSQLStringException(SQLException se) 113 { 114 if ((se.getMessage() != null && 115 se.getMessage().indexOf("Null SQL string passed.") >= 0) 116 || (se.getSQLState() != null && 117 (se.getSQLState().equals("XJ067")))) 118 return true; 119 return false; 120 } 121 122 static private boolean isInvalidParameterException(SQLException se) 123 { 124 if ((se.getMessage() != null && 125 se.getMessage().indexOf("Invalid parameter value") >= 0) 126 || (se.getMessage().indexOf("Invalid fetch size") >= 0) 127 || (se.getMessage().indexOf("Invalid fetch direction") >= 0) 128 || (se.getSQLState() != null && 129 (se.getSQLState().equals("XJ066")))) 130 return true; 131 return false; 132 } 133 134 static private boolean isValidOnScrollCursorsException(SQLException se) 135 { 136 if ((se.getMessage() != null && 137 se.getMessage().indexOf("' method is only allowed on scroll cursors.") >= 0) 138 || (se.getSQLState() != null && 139 (se.getSQLState().equals("XJ061")))) 140 return true; 141 return false; 142 } 143 144 static private boolean isInvalidMethodReturnException(SQLException se) 145 { 146 if (((se.getMessage() != null && 147 se.getMessage().indexOf("executeQuery method cannot be used for update.") >= 0) 148 || se.getMessage().indexOf("executeUpdate method cannot be used for query.") >= 0) 149 || (se.getSQLState() != null && 150 (se.getSQLState().equals("X0Y78") 151 || se.getSQLState().equals("X0Y79")))) 152 return true; 153 return false; 154 } 155 156 static private boolean isTableDoesNotExistException(SQLException se) 157 { 158 if (se.getSQLState() != null && 159 se.getSQLState().equals("42X05")) 160 return true; 161 return false; 162 } 163 164 static private boolean isReturnsInvalidResultSetException(SQLException se) 165 { 166 if ((se.getMessage() != null && 167 se.getMessage().indexOf("cannot be called with a statement that returns a ResultSet.") >= 0) 168 || (se.getSQLState() != null && 169 (se.getSQLState().equals("X0Y79")))) 170 return true; 171 return false; 172 } 173 } 174 | Popular Tags |