1738556 Primitive ODBC Driver
[csql.git] / test / performance / JDBCTest.java
blob794e7c3e19f5a4b00657b645f5bd63fb180f76dc
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));");
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) ");
15 cStmt.close();
16 con.commit();
18 PreparedStatement stmt = null, selStmt= null;
19 stmt = con.prepareStatement("INSERT INTO T1 (f1, f2) VALUES (?, ?);");
20 int count =0;
21 int ret =0;
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();
27 stmt.setInt(1, i);
28 stmt.setString(2, "DummyValue");
29 ret = stmt.executeUpdate();
30 if (ret != 1) break; //error
31 end = System.nanoTime();
32 if (i ==0) continue;
33 curr = end-start;
34 tot = tot + curr;
35 if (min > curr) min = curr;
36 if (max < curr) max = curr;
37 count++;
40 stmt.close();
41 con.commit();
42 System.out.print("Insert : " + count );
43 System.out.println(" Min:" + min+ " Max: "+max+" Avg: "+ tot/100 );
45 count=0;
46 start=0; end=0; curr=0;
47 min=100000; max=0;tot =0;
48 selStmt = con.prepareStatement("SELECT * from T1 where f1 = ?;");
49 ResultSet rs = null;
50 int intVal =0;
51 String strVal = null;
52 for (int i =0 ; i<= 100 ; i++) {
53 start = System.nanoTime();
54 selStmt.setInt(1, i);
55 rs = selStmt.executeQuery();
56 if (rs.next())
58 intVal = rs.getInt(1);
59 strVal = rs.getString(2);
62 rs.close();
63 end = System.nanoTime();
64 if (i ==0) continue;
65 //System.out.println("Tuple "+ intVal+ " "+ strVal);
66 curr = end-start;
67 tot = tot + curr;
68 if (min > curr) min = curr;
69 if (max < curr) max = curr;
70 count++;
72 selStmt.close();
73 con.commit();
74 System.out.print("Select : " + count);
75 System.out.println(" Min:" + min+ " Max: "+max+" Avg: "+ tot/100 );
77 count =0;
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();
83 stmt.setInt(2, i);
84 stmt.setString(1, "UpdatedValue");
85 ret = stmt.executeUpdate();
86 if (ret != 1) break; //error
87 end = System.nanoTime();
88 if (i ==0) continue;
89 curr = end-start;
90 tot = tot + curr;
91 if (min > curr) min = curr;
92 if (max < curr) max = curr;
93 count++;
95 stmt.close();
96 con.commit();
97 System.out.print("Update : " + count);
98 System.out.println(" Min:" + min+ " Max: "+max+" Avg: "+ tot/100 );
100 count =0;
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();
106 stmt.setInt(1, i);
107 ret = stmt.executeUpdate();
108 if (ret != 1) break; //error
109 end = System.nanoTime();
110 if (i ==0) continue;
111 curr = end-start;
112 tot = tot + curr;
113 if (min > curr) min = curr;
114 if (max < curr) max = curr;
115 count++;
117 stmt.close();
118 con.commit();
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");
124 cStmt.close();
126 con.close();
128 catch(Exception e) {
129 System.out.println("Exception in Test: "+e);
130 e.printStackTrace();