1 21 22 package org.apache.derbyTesting.functionTests.tests.lang; 23 24 import java.sql.Connection ; 25 import java.sql.DriverManager ; 26 import java.sql.Statement ; 27 import java.sql.PreparedStatement ; 28 import java.sql.ResultSet ; 29 import java.sql.ResultSetMetaData ; 30 import java.sql.DatabaseMetaData ; 31 import java.sql.SQLException ; 32 import java.sql.SQLWarning ; 33 34 import org.apache.derby.tools.ij; 35 import org.apache.derby.tools.JDBCDisplayUtil; 36 37 42 public class AIjdbc 43 { 44 45 public static void main(String [] args) { 46 System.out.println("Test AIjdbc starting"); 47 boolean passed = true; 48 49 try 50 { 51 Connection conn; 52 53 ij.getPropertyArg(args); 56 conn = ij.startJBMS(); 57 58 passed = createTable(conn) && passed; 60 61 passed = testSelect(conn) && passed; 63 64 passed = testSelectView(conn) && passed; 66 } 67 catch (Throwable e) 68 { 69 passed = false; 70 System.out.println("FAIL -- unexpected exception:"); 71 JDBCDisplayUtil.ShowException(System.out, e); 72 } 73 74 if (passed) 75 System.out.println("PASS"); 76 else 77 System.out.println("FAIL"); 78 79 System.out.println("Test AIjdbc finished"); 80 } 81 82 private static boolean createTable(Connection conn) throws SQLException 83 { 84 Statement s; 85 boolean passed = true; 86 87 System.out.println("Test AIjdbc:creating objects"); 88 89 try 90 { 91 s = conn.createStatement(); 92 s.execute("create table tab1 (x int, y int generated always as identity,z char(2))"); 93 s.execute("create view tab1_view (a,b) as select y,y+1 from tab1"); 94 } 95 catch (SQLException se) 96 { 97 passed = false; 98 JDBCDisplayUtil.ShowSQLException(System.out,se); 99 } 100 101 return passed; 102 } 103 104 private static boolean testSelect(Connection conn) 105 { 106 Statement s; 107 boolean passed = true; 108 109 System.out.println("Test AIjdbc:select from base table"); 110 111 try 112 { 113 s = conn.createStatement(); 114 ResultSet rs = s.executeQuery("select x,z from tab1"); 115 ResultSetMetaData rsmd = rs.getMetaData(); 116 117 if (rsmd.getColumnCount() != 2) 118 throw new SQLException ("column count doesn't match"); 119 if (rsmd.isAutoIncrement(1)) 120 throw new SQLException ("column 1 is NOT ai!"); 121 if (rsmd.isAutoIncrement(2)) 122 throw new SQLException ("column 2 is NOT ai!"); 123 rs.close(); 124 125 rs = s.executeQuery("select y, x,z from tab1"); 126 rsmd = rs.getMetaData(); 127 if (rsmd.getColumnCount() != 3) 128 throw new SQLException ("column count doesn't match"); 129 if (!rsmd.isAutoIncrement(1)) 130 throw new SQLException ("column 1 IS ai!"); 131 if (rsmd.isAutoIncrement(2)) 132 throw new SQLException ("column 2 is NOT ai!"); 133 if (rsmd.isAutoIncrement(3)) 134 throw new SQLException ("column 2 is NOT ai!"); 135 rs.close(); 136 } 137 catch (SQLException se) 138 { 139 passed = false; 140 JDBCDisplayUtil.ShowSQLException(System.out,se); 141 142 } 143 return passed; 144 } 145 146 private static boolean testSelectView(Connection conn) 147 { 148 boolean passed = true; 149 System.out.println("Test AIjdbc:select from view"); 150 151 try 152 { 153 Statement s; 154 s = conn.createStatement(); 155 ResultSet rs = s.executeQuery("select * from tab1_view"); 156 ResultSetMetaData rsmd = rs.getMetaData(); 157 158 if (rsmd.getColumnCount() != 2) 159 throw new SQLException ("column count doesn't match"); 160 if (!rsmd.isAutoIncrement(1)) 161 throw new SQLException ("column 1 IS ai!"); 162 if (rsmd.isAutoIncrement(2)) 163 throw new SQLException ("column 1 is NOT ai!"); 164 } 165 catch (SQLException sqle) 166 { 167 passed = false; 168 JDBCDisplayUtil.ShowSQLException(System.out,sqle); 169 } 170 return passed; 171 } 172 } 173 | Popular Tags |