1 21 22 package org.apache.derbyTesting.functionTests.tests.derbynet; 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 30 import org.apache.derby.tools.ij; 31 36 37 public class executeUpdate 38 { 39 40 public static void main (String args[]) 41 { 42 try 43 { 44 System.out.println("executeUpdate Test Starts"); 45 ij.getPropertyArg(args); 47 Connection conn = ij.startJBMS(); 48 49 if (conn == null) 50 { 51 System.out.println("conn didn't work"); 52 return; 53 } 54 Statement stmt = conn.createStatement(); 55 int rowCount = stmt.executeUpdate("create table exup(a int)"); 56 if (rowCount != 0) 57 System.out.println("FAIL - non zero return count on create table"); 58 else 59 System.out.println("PASS - create table"); 60 rowCount = stmt.executeUpdate("insert into exup values(1)"); 61 if (rowCount != 1) 62 System.out.println("FAIL - expected row count 1, got " + rowCount); 63 else 64 System.out.println("PASS - insert 1 row"); 65 rowCount = stmt.executeUpdate("insert into exup values(2),(3),(4)"); 66 if (rowCount != 3) 67 System.out.println("FAIL - expected row count 3, got " + rowCount); 68 else 69 System.out.println("PASS - insert 3 rows"); 70 System.out.println("Rows in table should be 1,2,3,4"); 71 ResultSet rs = stmt.executeQuery("select * from exup"); 72 int i = 1; 73 boolean fail = false; 74 int val; 75 while (rs.next()) 76 { 77 if (i++ != (val = rs.getInt(1))) 78 { 79 System.out.println("FAIL - expecting " + i + " got " + val); 80 fail = true; 81 } 82 } 83 if (i != 5) 84 System.out.println("FAIL - too many rows in table"); 85 else if (!fail) 86 System.out.println("PASS - correct rows in table"); 87 rs.close(); 88 rowCount = stmt.executeUpdate("drop table exup"); 89 if (rowCount != 0) 90 System.out.println("FAIL - non zero return count on drop table"); 91 else 92 System.out.println("PASS - drop table"); 93 stmt.close(); 94 System.out.println("executeUpdate Test ends"); 95 96 } 97 catch (java.sql.SQLException e) { 98 e.printStackTrace(); 99 } 100 catch (Exception e) 101 { 102 e.printStackTrace(); 103 } 104 } 105 } 106 | Popular Tags |