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 (194));");
12 System
.out
.println("Table t1 created");
13 cStmt
.execute("CREATE INDEX IDX ON T1 (f1) PRIMARY;");
14 System
.out
.println("Primary Index created on T1 (f1) ");
18 PreparedStatement stmt
= null, selStmt
= null;
19 stmt
= con
.prepareStatement("INSERT INTO T1 (f1, f2) VALUES (?, ?);");
22 stmt
.setString(2, "DummyValue");
23 long start
=0, end
=0, curr
=0;
24 long min
=100000, max
=0, tot
=0;
25 for (int i
=0 ; i
<= 100 ; i
++) {
26 start
= System
.nanoTime();
28 stmt
.setString(2, "DummyValue");
29 ret
= stmt
.executeUpdate();
30 if (ret
!= 1) break; //error
31 end
= System
.nanoTime();
35 if (min
> curr
) min
= curr
;
36 if (max
< curr
) max
= curr
;
42 System
.out
.print("Insert : " + count
);
43 System
.out
.println(" Min:" + min
+ " Max: "+max
+" Avg: "+ tot
/100 );
46 start
=0; end
=0; curr
=0;
47 min
=100000; max
=0;tot
=0;
48 selStmt
= con
.prepareStatement("SELECT * from T1 where f1 = ?;");
52 for (int i
=0 ; i
<= 100 ; i
++) {
53 start
= System
.nanoTime();
55 rs
= selStmt
.executeQuery();
58 intVal
= rs
.getInt(1);
59 strVal
= rs
.getString(2);
63 end
= System
.nanoTime();
65 //System.out.println("Tuple "+ intVal+ " "+ strVal);
68 if (min
> curr
) min
= curr
;
69 if (max
< curr
) max
= curr
;
74 System
.out
.print("Select : " + count
);
75 System
.out
.println(" Min:" + min
+ " Max: "+max
+" Avg: "+ tot
/100 );
78 start
=0; end
=0; curr
=0;
79 min
=100000; max
=0;tot
=0;
80 stmt
= con
.prepareStatement("UPDATE T1 SET f2 = ? WHERE f1 = ?;");
81 for (int i
=0 ; i
<= 100 ; i
++) {
82 start
= System
.nanoTime();
84 stmt
.setString(1, "UpdatedValue");
85 ret
= stmt
.executeUpdate();
86 if (ret
!= 1) break; //error
87 end
= System
.nanoTime();
91 if (min
> curr
) min
= curr
;
92 if (max
< curr
) max
= curr
;
97 System
.out
.print("Update : " + count
);
98 System
.out
.println(" Min:" + min
+ " Max: "+max
+" Avg: "+ tot
/100 );
101 start
=0; end
=0; curr
=0;
102 min
=100000; max
=0;tot
=0;
103 stmt
= con
.prepareStatement("DELETE FROM T1 WHERE f1 = ?;");
104 for (int i
=0 ; i
<= 100 ; i
++) {
105 start
= System
.nanoTime();
107 ret
= stmt
.executeUpdate();
108 if (ret
!= 1) break; //error
109 end
= System
.nanoTime();
113 if (min
> curr
) min
= curr
;
114 if (max
< curr
) max
= curr
;
119 System
.out
.print("Delete : " + count
);
120 System
.out
.println(" Min:" + min
+ " Max: "+max
+" Avg: "+ tot
/100 );
122 //cStmt.execute("DROP TABLE T1;");
123 System
.out
.println("Dropped table T1");
129 System
.out
.println("Exception in Test: "+e
);