1 //Test DML statement with parameters
5 public static void main(String
[] args
)
9 Class
.forName("csql.jdbc.JdbcSqlDriver");
10 Connection con
= DriverManager
.getConnection("jdbc:csql", "root", "manager");
11 Statement cStmt
= con
.createStatement();
12 cStmt
.execute("CREATE TABLE T1 (f1 integer, f2 char (20));");
13 cStmt
.execute("CREATE INDEX IDX ON T1 ( f1);");
15 PreparedStatement stmt
= null, selStmt
= null;
16 stmt
= con
.prepareStatement("INSERT INTO T1 VALUES (?, ?);");
17 for (int i
=0 ; i
< 10 ; i
++) {
19 stmt
.setString(2, String
.valueOf(i
+100));
24 selStmt
= con
.prepareStatement("SELECT * from T1 where f1 = ?;");
26 for (int i
=0 ; i
< 10 ; i
++) {
28 rs
= selStmt
.executeQuery();
31 System
.out
.println("Tuple value is " + rs
.getInt(1)+ " "+ rs
.getString(2));
36 stmt
= con
.prepareStatement("UPDATE T1 SET f2 = ? WHERE f1 = ?;");
37 for (int i
=0 ; i
< 10 ; i
+=2) {
38 stmt
.setString(1, String
.valueOf(i
+200));
40 ret
= stmt
.executeUpdate();
46 System
.out
.println("After update, listing tuples:");
47 for (int i
=0 ; i
< 10 ; i
++) {
49 rs
= selStmt
.executeQuery();
52 System
.out
.println("Tuple value is " + rs
.getInt(1)+ " "+ rs
.getString(2));
60 stmt
= con
.prepareStatement("DELETE FROM T1 WHERE f1 = ?;");
61 for (int i
=0 ; i
< 10 ; i
+=3) {
63 ret
= stmt
.executeUpdate();
69 System
.out
.println("After delete, listing tuples:");
70 for (int i
=0 ; i
< 10 ; i
++) {
72 rs
= selStmt
.executeQuery();
75 System
.out
.println("Tuple value is " + rs
.getInt(1)+ " "+ rs
.getString(2));
80 cStmt
.execute("DROP TABLE T1 ;");
83 System
.out
.println("Exception in Test: "+e
);