1 21 package org.apache.derbyTesting.functionTests.tests.derbynet; 22 23 import java.sql.*; 24 import java.util.Vector ; 25 import java.util.Properties ; 26 import java.io.File ; 27 28 import java.io.BufferedOutputStream ; 29 import org.apache.derbyTesting.functionTests.harness.TimedProcess; 30 import org.apache.derbyTesting.functionTests.util.TestUtil; 31 32 36 37 public class badConnection 38 { 39 40 private static Properties properties = new java.util.Properties (); 41 42 private static String dbNotFoundDB = "notthere"; 43 private static String invalidAttrDB = "testbase;upgrade=notValidValue"; 44 private static String derbynetDB = "testbase"; 45 46 47 private static Connection newConn(String database,Properties properties) throws Exception 48 { 49 Connection conn = null; 50 String databaseURL = TestUtil.getJdbcUrlPrefix() + database; 51 53 try { 54 conn = DriverManager.getConnection(databaseURL, properties); 55 if (conn == null) 56 System.out.println("create connection didn't work"); 57 else 58 System.out.println("Connection made\n"); 59 60 } 61 catch (SQLException se) 62 { 63 showSQLException(se); 64 } 65 66 return conn; 67 } 68 69 private static void showSQLException(SQLException e) 70 { 71 System.out.println("passed SQLException all the way to client, then thrown by client..."); 72 System.out.println("SQLState is: "+e.getSQLState()); 73 System.out.println("vendorCode is: "+e.getErrorCode()); 74 System.out.println("nextException is: "+e.getNextException()); 75 System.out.println("reason is: "+e.getMessage() +"\n\n"); 76 } 77 78 public static void main (String args[]) throws Exception 79 { 80 81 try 82 { 83 TestUtil.loadDriver(); 84 System.out.println("No user/password (Client error)"); 85 Connection conn1 = newConn(derbynetDB, properties); 86 87 System.out.println("Database not Found (RDBNFNRM)"); 88 properties.put ("user", "admin"); 89 properties.put ("password", "admin"); 90 conn1 = newConn(dbNotFoundDB, properties); 91 if (conn1 != null) 92 conn1.close(); 93 94 System.out.println("Invalid Attribute value (RDBAFLRM)"); 95 conn1 = newConn(invalidAttrDB, properties); 96 if (conn1 != null) 97 conn1.close(); 98 99 } 100 catch (SQLException se) 101 { 102 showSQLException(se); 103 } 104 catch (Exception e) 105 { 106 e.printStackTrace(); 107 } 108 } 109 110 111 } 112 | Popular Tags |