1 21 package org.apache.derbyTesting.functionTests.tests.derbynet; 22 23 import java.io.PrintWriter ; 24 import java.sql.Connection ; 25 import java.sql.SQLException ; 26 import java.sql.Statement ; 27 28 import org.apache.derby.tools.ij; 29 30 36 public class TestEnc { 37 38 private PrintWriter out; 39 40 public static void main(String args[]) throws Exception { 41 new TestEnc().go(args); 42 } 43 44 public void go(String [] args) throws Exception { 45 46 ij.getPropertyArg(args); 50 Connection conn = ij.startJBMS(); 51 52 conn.setAutoCommit(true); 53 Statement stmt = conn.createStatement(); 54 55 try { 60 stmt.execute("select bla"); 61 } catch (SQLException e) { 62 if (e.getSQLState().equals("42X01")) { 63 System.out.println("Message "+e.getMessage()); 64 } 65 else 66 handleSQLException("DERBY-583",e,false); 67 } 68 finally { 69 if (stmt != null) 70 stmt.close(); 71 } 72 } 73 74 public void handleSQLException(String method, 75 SQLException e, 76 boolean expected) throws Exception { 77 do { 78 out.print("\t" + method + " \tException " + 79 "SQLSTATE:" + e.getSQLState()); 80 if (expected) 81 out.println(" (EXPECTED)"); 82 else 83 e.printStackTrace(out); 84 e = e.getNextException(); 85 } while (e != null); 86 87 } 88 } 89 | Popular Tags |