1 21 22 package org.apache.derbyTesting.functionTests.tests.jdbcapi; 23 24 import java.sql.Connection ; 25 import java.sql.ResultSet ; 26 import java.sql.SQLException ; 27 import java.sql.Statement ; 28 29 import org.apache.derby.tools.ij; 30 import org.apache.derby.iapi.reference.JDBC30Translation; 31 32 36 37 public class statementJdbc30 { 38 39 public static void main(String [] args) { 40 Connection con; 41 ResultSet rs; 42 Statement stmt; 43 44 System.out.println("Test statementJdbc30 starting"); 45 46 try 47 { 48 ij.getPropertyArg(args); 51 con = ij.startJBMS(); 52 53 54 stmt = con.createStatement(); 55 56 stmt.execute("create table tab1 (i int, s smallint, r real)"); 58 stmt.executeUpdate("insert into tab1 values(1, 2, 3.1)"); 59 60 rs = stmt.executeQuery("select * from tab1"); 62 rs.next(); 63 64 System.out.println("trying stmt.getMoreResults(int) :"); 65 stmt.getMoreResults(JDBC30Translation.CLOSE_CURRENT_RESULT); 66 67 System.out.println("trying stmt.executeUpdate(String, int) :"); 68 stmt.executeUpdate("insert into tab1 values(2, 3, 4.1)", JDBC30Translation.NO_GENERATED_KEYS); 69 70 System.out.println("trying stmt.executeUpdate(String, int[]) :"); 71 int[] columnIndexes = new int[2]; 72 columnIndexes[0] = 1; 73 columnIndexes[1] = 2; 74 try { 75 stmt.executeUpdate("insert into tab1 values(2, 3, 4.1)", columnIndexes); 76 } catch (SQLException ex) { 77 dumpExpectedSQLExceptions(ex); 78 } 79 80 System.out.println("trying stmt.executeUpdate(String, String[]) :"); 81 String [] columnNames = new String [2]; 82 columnNames[0] = "I"; 83 columnNames[1] = "S"; 84 try { 85 stmt.executeUpdate("insert into tab1 values(2, 3, 4.1)", columnNames); 86 } catch (SQLException ex) { 87 dumpExpectedSQLExceptions(ex); 88 } 89 90 System.out.println("trying stmt.execute(String, int) :"); 91 stmt.execute("select * from tab1", JDBC30Translation.NO_GENERATED_KEYS); 92 93 System.out.println("trying stmt.execute(String, int[]) :"); 94 try { 95 stmt.execute("insert into tab1 values(2, 3, 4.1)", columnIndexes); 96 } catch (SQLException ex) { 97 dumpExpectedSQLExceptions(ex); 98 } 99 100 System.out.println("trying stmt.execute(String, String[]) :"); 101 try { 102 stmt.execute("insert into tab1 values(2, 3, 4.1)", columnNames); 103 } catch (SQLException ex) { 104 dumpExpectedSQLExceptions(ex); 105 } 106 107 System.out.println("trying stmt.getResultSetHoldability() :"); 108 stmt.getResultSetHoldability(); 109 110 System.out.println("trying stmt.getGeneratedKeys() :"); 111 stmt.getGeneratedKeys(); 112 113 rs.close(); 114 stmt.close(); 115 con.close(); 116 117 } 118 catch (SQLException e) { 119 System.out.println("Expected : " + e.getMessage()); 120 } 121 catch (Throwable e) { 122 System.out.println("FAIL -- unexpected exception: "+e); 123 e.printStackTrace(); 124 } 125 126 System.out.println("Test statementJdbc30 finished"); 127 } 128 129 public static void dumpExpectedSQLExceptions (SQLException se) { 130 System.out.println("PASS -- expected exception"); 131 while (se != null) 132 { 133 System.out.println("SQLSTATE("+se.getSQLState()+"): "+se); 134 se = se.getNextException(); 135 } 136 } 137 } 138 | Popular Tags |