2 public class jdbcexample
4 public static void main(String
[] args
)
8 Class
.forName("csql.jdbc.JdbcSqlDriver");
9 Connection con
= DriverManager
.getConnection("jdbc:csql", "root", "manager");
10 Statement cStmt
= con
.createStatement();
11 cStmt
.execute("CREATE TABLE T1 (f1 integer, f2 char (20));");
12 System
.out
.println("Table t1 created");
13 cStmt
.execute("CREATE INDEX IDX ON T1 ( f1);");
14 System
.out
.println("Index created on T1 (f1) ");
18 PreparedStatement stmt
= null, selStmt
= null;
19 stmt
= con
.prepareStatement("INSERT INTO T1 (f1, f2) VALUES (?, ?);");
22 for (int i
=0 ; i
< 10 ; i
++) {
24 stmt
.setString(2, String
.valueOf(i
+100));
25 ret
= stmt
.executeUpdate();
26 if (ret
!= 1) break; //error
31 System
.out
.println("Total Rows inserted " + count
);
34 stmt
= con
.prepareStatement("UPDATE T1 SET f2 = ? WHERE f1 = ?;");
35 for (int i
=0 ; i
< 10 ; i
+=2) {
36 stmt
.setString(1, String
.valueOf(i
+200));
38 ret
= stmt
.executeUpdate();
39 if (ret
!= 1) break; //error
44 System
.out
.println("Total Rows updated " + count
);
47 stmt
= con
.prepareStatement("DELETE FROM T1 WHERE f1 = ?;");
48 for (int i
=0 ; i
< 10 ; i
+=3) {
50 ret
= stmt
.executeUpdate();
51 if (ret
!= 1) break; //error
56 System
.out
.println("Total Rows deleted " + count
);
59 selStmt
= con
.prepareStatement("SELECT * from T1 where f1 = ?;");
61 for (int i
=0 ; i
< 10 ; i
++) {
63 rs
= selStmt
.executeQuery();
66 System
.out
.println("Tuple value is " + rs
.getInt(1)+ " "+ rs
.getString(2));
73 System
.out
.println("Total Rows selected " + count
);
75 cStmt
.execute("DROP TABLE T1;");
76 System
.out
.println("Dropped table T1");
82 System
.out
.println("Exception in Test: "+e
);