Fixing system/config/test002 failed test
[csql.git] / test / performance / JDBCTest.java
blob982853bdba2163637e0850215521a2b59d980850
1 import java.sql.*;
2 public class JDBCTest
4 public static void main(String[] args)
6 try
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), primary key(f1));");
12 System.out.println("Table t1 created");
13 cStmt.close();
14 con.commit();
16 PreparedStatement stmt = null, selStmt= null;
17 stmt = con.prepareStatement("INSERT INTO T1 (f1, f2) VALUES (?, ?);");
18 int count =0;
19 int ret =0;
20 stmt.setString(2, "DummyValue");
21 long start =0, end =0, curr =0;
22 long min =100000, max =0, tot =0;
23 for (int i =0 ; i<= 100 ; i++) {
24 start = System.nanoTime();
25 stmt.setInt(1, i);
26 stmt.setString(2, "DummyValue");
27 ret = stmt.executeUpdate();
28 if (ret != 1) break; //error
29 end = System.nanoTime();
30 if (i ==0) continue;
31 curr = end-start;
32 tot = tot + curr;
33 if (min > curr) min = curr;
34 if (max < curr) max = curr;
35 count++;
38 stmt.close();
39 con.commit();
40 System.out.print("Insert : " + count );
41 System.out.println(" Min:" + min+ " Max: "+max+" Avg: "+ tot/100 );
43 count=0;
44 start=0; end=0; curr=0;
45 min=100000; max=0;tot =0;
46 selStmt = con.prepareStatement("SELECT * from T1 where f1 = ?;");
47 ResultSet rs = null;
48 int intVal =0;
49 String strVal = null;
50 for (int i =0 ; i<= 100 ; i++) {
51 start = System.nanoTime();
52 selStmt.setInt(1, i);
53 rs = selStmt.executeQuery();
54 if (rs.next())
56 intVal = rs.getInt(1);
57 strVal = rs.getString(2);
60 rs.close();
61 end = System.nanoTime();
62 if (i ==0) continue;
63 //System.out.println("Tuple "+ intVal+ " "+ strVal);
64 curr = end-start;
65 tot = tot + curr;
66 if (min > curr) min = curr;
67 if (max < curr) max = curr;
68 count++;
70 selStmt.close();
71 con.commit();
72 System.out.print("Select : " + count);
73 System.out.println(" Min:" + min+ " Max: "+max+" Avg: "+ tot/100 );
75 count =0;
76 start=0; end=0; curr=0;
77 min=100000; max=0;tot =0;
78 stmt = con.prepareStatement("UPDATE T1 SET f2 = ? WHERE f1 = ?;");
79 for (int i =0 ; i<= 100 ; i++) {
80 start = System.nanoTime();
81 stmt.setInt(2, i);
82 stmt.setString(1, "UpdatedValue");
83 ret = stmt.executeUpdate();
84 if (ret != 1) break; //error
85 end = System.nanoTime();
86 if (i ==0) continue;
87 curr = end-start;
88 tot = tot + curr;
89 if (min > curr) min = curr;
90 if (max < curr) max = curr;
91 count++;
93 stmt.close();
94 con.commit();
95 System.out.print("Update : " + count);
96 System.out.println(" Min:" + min+ " Max: "+max+" Avg: "+ tot/100 );
98 count =0;
99 start=0; end=0; curr=0;
100 min=100000; max=0;tot =0;
101 stmt = con.prepareStatement("DELETE FROM T1 WHERE f1 = ?;");
102 for (int i =0 ; i<= 100 ; i++) {
103 start = System.nanoTime();
104 stmt.setInt(1, i);
105 ret = stmt.executeUpdate();
106 if (ret != 1) break; //error
107 end = System.nanoTime();
108 if (i ==0) continue;
109 curr = end-start;
110 tot = tot + curr;
111 if (min > curr) min = curr;
112 if (max < curr) max = curr;
113 count++;
115 stmt.close();
116 con.commit();
117 System.out.print("Delete : " + count);
118 System.out.println(" Min:" + min+ " Max: "+max+" Avg: "+ tot/100 );
120 //cStmt.execute("DROP TABLE T1;");
121 System.out.println("Dropped table T1");
122 cStmt.close();
124 con.close();
126 catch(Exception e) {
127 System.out.println("Exception in Test: "+e);
128 e.printStackTrace();