1 //Test DML statement with rollback
5 public static void main(String
[] args
)
9 Class
.forName("csql.jdbc.JdbcSqlDriver");
10 Connection con
= DriverManager
.getConnection("jdbc:csql://localhost:5678", "root", "manager");
11 Statement cStmt
= con
.createStatement();
12 con
.setAutoCommit(false);
14 cStmt
.execute("CREATE TABLE T1 (f1 integer, f2 char (20));");
16 PreparedStatement stmt
= null;
17 stmt
= con
.prepareStatement("INSERT INTO T1 VALUES (?, ?);");
18 for (int i
=0 ; i
< 10 ; i
++) {
20 stmt
.setString(2, String
.valueOf(i
+100));
21 ret
= stmt
.executeUpdate();
27 cStmt
.execute("UPDATE T1 set f2='2' where f1 = 2;");
28 ret
= cStmt
.executeUpdate("INSERT INTO T1 values (100, '100');");
29 if (ret
!= 1) System
.out
.println("Insert error");
30 ret
= cStmt
.executeUpdate("DELETE FROM T1 WHERE f1 = 4;");
31 if (ret
!= 1) System
.out
.println("Delete error");
34 System
.out
.println("After rollback, listing tuples:");
35 ResultSet rs
= cStmt
.executeQuery("SELECT * from T1;");
38 System
.out
.println("Tuple value is " + rs
.getInt(1)+ " "+ rs
.getString(2));
42 cStmt
.executeUpdate("DROP TABLE T1;");
46 System
.out
.println("Exception in Test: "+e
);