2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
14 public class connect
implements Runnable
17 PreparedStatement stmt
;
24 connect(int i
,int ty
,int record
)
26 System
.out
.println("thread "+ i
);
34 public static Connection
getDBConn() throws Exception
36 Class
.forName("csql.jdbc.JdbcSqlDriver");
37 Connection con
= DriverManager
.getConnection("jdbc:csql:", "root", "manager");
42 if(0==type
) insertTest();
43 else if(1==type
) selectTest();
44 else if(2==type
) updateTest();
45 else if(3==type
) deleteTest();
49 public void insertTest()
52 //Class.forName("csql.jdbc.JdbcSqlDriver");
53 //con = DriverManager.getConnection("jdbc:csql:","root","manager");
55 stmt
= con
.prepareStatement("insert into emp values (?, 'SECOND');");
56 long count
= 0, recordCount
=0;
58 long start
= 0,end
= 0,curr
= 0;
60 for(int i
=0; i
<totalrecord
; i
++){
61 stmt
.setInt(1, totalrecord
*thid
+i
);
62 start
= System
.nanoTime();
64 ret
= stmt
.executeUpdate();
68 System
.out
.println("Retry -1 Exception in Test=1: "+e1
);
69 ret
= stmt
.executeUpdate();
72 System
.out
.println("Retry -2 Exception in Test=2: "+e
);
73 ret
= stmt
.executeUpdate();
78 end
= System
.nanoTime();
85 long val
= tot
/totalrecord
;
86 System
.out
.println("Thread id "+this.thid
+" Total rec: "+count
+" Avgtime :"+val
);
87 System
.out
.println("Total Record Insert: "+count
);
91 System
.out
.println("Exception in Test: "+e
+"Thread NO"+thid
);
96 public void selectTest()
99 //Class.forName("csql.jdbc.JdbcSqlDriver");
100 //con = DriverManager.getConnection("jdbc:csql:","root","manager");
102 stmt
= con
.prepareStatement("select * from emp where f1=?");
104 long count
= 0, recordCount
=0;
106 long start
= 0,end
= 0,curr
= 0;
108 for(int i
=0; i
<totalrecord
; i
++){
109 stmt
.setInt(1, totalrecord
*thid
+i
);
110 start
= System
.nanoTime();
112 rs
= stmt
.executeQuery();
116 System
.out
.println("Retry-1"+ e1
);
117 rs
= stmt
.executeQuery();
120 System
.out
.println("Retry-2"+ e1
);
121 rs
= stmt
.executeQuery();
129 end
= System
.nanoTime();
136 long val
= tot
/totalrecord
;
137 System
.out
.println("Thread id "+this.thid
+"Total select "+recordCount
+" Avgtime :"+val
);
138 System
.out
.println("Total Record select "+recordCount
+ " " + tot
+ " "+ totalrecord
);
140 }catch(Exception e
) {
141 System
.out
.println("Exception in Test: "+e
+"Thread NO"+thid
);
146 public void deleteTest()
150 //Class.forName("csql.jdbc.JdbcSqlDriver");
151 //con = DriverManager.getConnection("jdbc:csql:","root","manager");
153 stmt
= con
.prepareStatement("delete from emp where f1=?");
154 long count
= 0, recordCount
=0;
158 long start
= 0,end
= 0,curr
= 0;
160 for(int i
=0; i
<totalrecord
; i
++){
161 stmt
.setInt(1, totalrecord
*thid
+i
);
162 start
= System
.nanoTime();
164 ret
= stmt
.executeUpdate();
168 ret
= stmt
.executeUpdate();
171 // System.out.println("Exception in Test=2: "+e);
172 ret
= stmt
.executeUpdate();
176 end
= System
.nanoTime();
182 long val
= tot
/totalrecord
;
183 System
.out
.println("Total Record Delete: "+count
);
185 }catch(Exception e
) {
186 System
.out
.println("Exception in Test: "+e
+"Thread NO"+thid
);
190 public void updateTest()
193 //Class.forName("csql.jdbc.JdbcSqlDriver");
194 //con = DriverManager.getConnection("jdbc:csql:","root","manager");
196 stmt
= con
.prepareStatement("update emp set f2='india' where f1=?");
197 long count
= 0, recordCount
=0;
201 long start
= 0,end
= 0,curr
= 0;
203 for(int i
=0; i
<totalrecord
; i
++){
204 stmt
.setInt(1, totalrecord
*thid
+i
);
205 start
= System
.nanoTime();
207 ret
= stmt
.executeUpdate();
211 ret
= stmt
.executeUpdate();
214 //System.out.println("Exception in Test=2: "+e);
215 ret
= stmt
.executeUpdate();
219 end
= System
.nanoTime();
225 long val
= tot
/totalrecord
;
226 System
.out
.println("Thread id "+this.thid
+" Total rec Update: "+count
+" Avgtime :"+val
);
227 System
.out
.println("Total Record Update: "+count
);
229 }catch(Exception e
) {
230 System
.out
.println("Exception in Test: "+e
+"Thread NO"+thid
);
235 public void selectTest1()
238 //Class.forName("csql.jdbc.JdbcSqlDriver");
239 //con = DriverManager.getConnection("jdbc:csql:","root","manager");
241 stmt
= con
.prepareStatement("select * from emp where f1>=? and f1<?");
243 long count
= 0, recordCount
=0;
245 long start
= 0,end
= 0,curr
= 0;
247 for(int i
=0; i
<totalrecord
/100; i
++){
248 stmt
.setInt(1, totalrecord
*thid
+i
);
249 stmt
.setInt(2, totalrecord
*thid
+i
+100);
250 start
= System
.nanoTime();
252 rs
= stmt
.executeQuery();
256 rs
= stmt
.executeQuery();
259 rs
= stmt
.executeQuery();
267 end
= System
.nanoTime();
273 long val
= tot
/totalrecord
;
274 System
.out
.println("Thread id "+this.thid
+"Total select "+recordCount
+" Avgtime :"+val
);
275 System
.out
.println("Total Record select "+recordCount
);
277 }catch(Exception e
) {
278 System
.out
.println("Exception in Test: "+e
+"Thread NO"+thid
);