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
;
23 connect(int i
,int ty
,int record
)
25 System
.out
.println("thread "+ i
);
34 if(0==type
) insertTest();
35 else if(1==type
) selectTest();
36 else if(2==type
) updateTest();
37 else if(3==type
) deleteTest();
41 public void insertTest()
44 Class
.forName("csql.jdbc.JdbcSqlDriver");
45 con
= DriverManager
.getConnection("jdbc:csql:","root","manager");
46 stmt
= con
.prepareStatement("insert into emp values (?, 'SECOND');");
47 long count
= 0, recordCount
=0;
49 long start
= 0,end
= 0,curr
= 0;
51 for(int i
=0; i
<totalrecord
; i
++){
52 stmt
.setInt(1, totalrecord
*thid
+i
);
53 start
= System
.nanoTime();
55 ret
= stmt
.executeUpdate();
59 ret
= stmt
.executeUpdate();
62 // System.out.println("Exception in Test=2: "+e);
63 ret
= stmt
.executeUpdate();
68 end
= System
.nanoTime();
74 long val
= tot
/totalrecord
;
75 //System.out.println("Thread id "+this.thid+" Total rec: "+count+" Avgtime :"+val);
76 System
.out
.println("Total Record Insert: "+count
);
80 System
.out
.println("Exception in Test: "+e
+"Thread NO"+thid
);
85 public void selectTest()
88 Class
.forName("csql.jdbc.JdbcSqlDriver");
89 con
= DriverManager
.getConnection("jdbc:csql:","root","manager");
90 stmt
= con
.prepareStatement("select * from emp where f1=?");
92 long count
= 0, recordCount
=0;
94 long start
= 0,end
= 0,curr
= 0;
96 for(int i
=0; i
<totalrecord
; i
++){
97 stmt
.setInt(1, totalrecord
*thid
+i
);
98 start
= System
.nanoTime();
100 rs
= stmt
.executeQuery();
104 rs
= stmt
.executeQuery();
107 rs
= stmt
.executeQuery();
115 end
= System
.nanoTime();
121 long val
= tot
/totalrecord
;
122 //System.out.println("Thread id "+this.thid+"Total select "+recordCount+" Avgtime :"+val);
123 System
.out
.println("Total Record select "+recordCount
);
125 }catch(Exception e
) {
126 System
.out
.println("Exception in Test: "+e
+"Thread NO"+thid
);
131 public void deleteTest()
135 Class
.forName("csql.jdbc.JdbcSqlDriver");
136 con
= DriverManager
.getConnection("jdbc:csql:","root","manager");
137 stmt
= con
.prepareStatement("delete from emp where f1=?");
138 long count
= 0, recordCount
=0;
142 long start
= 0,end
= 0,curr
= 0;
144 for(int i
=0; i
<totalrecord
; i
++){
145 stmt
.setInt(1, totalrecord
*thid
+i
);
146 start
= System
.nanoTime();
148 ret
= stmt
.executeUpdate();
152 ret
= stmt
.executeUpdate();
155 // System.out.println("Exception in Test=2: "+e);
156 ret
= stmt
.executeUpdate();
160 end
= System
.nanoTime();
166 long val
= tot
/totalrecord
;
167 System
.out
.println("Total Record Delete: "+count
);
169 }catch(Exception e
) {
170 System
.out
.println("Exception in Test: "+e
+"Thread NO"+thid
);
174 public void updateTest()
177 Class
.forName("csql.jdbc.JdbcSqlDriver");
178 con
= DriverManager
.getConnection("jdbc:csql:","root","manager");
179 stmt
= con
.prepareStatement("update emp set f2='india' where f1=?");
180 long count
= 0, recordCount
=0;
184 long start
= 0,end
= 0,curr
= 0;
186 for(int i
=0; i
<totalrecord
; i
++){
187 stmt
.setInt(1, totalrecord
*thid
+i
);
188 start
= System
.nanoTime();
190 ret
= stmt
.executeUpdate();
194 ret
= stmt
.executeUpdate();
197 //System.out.println("Exception in Test=2: "+e);
198 ret
= stmt
.executeUpdate();
202 end
= System
.nanoTime();
208 long val
= tot
/totalrecord
;
209 //System.out.println("Thread id "+this.thid+" Total rec Update: "+count+" Avgtime :"+val);
210 System
.out
.println("Total Record Update: "+count
);
212 }catch(Exception e
) {
213 System
.out
.println("Exception in Test: "+e
+"Thread NO"+thid
);
218 public void selectTest1()
221 Class
.forName("csql.jdbc.JdbcSqlDriver");
222 con
= DriverManager
.getConnection("jdbc:csql:","root","manager");
223 stmt
= con
.prepareStatement("select * from emp where f1>=? and f1<?");
225 long count
= 0, recordCount
=0;
227 long start
= 0,end
= 0,curr
= 0;
229 for(int i
=0; i
<totalrecord
/100; i
++){
230 stmt
.setInt(1, totalrecord
*thid
+i
);
231 stmt
.setInt(2, totalrecord
*thid
+i
+100);
232 start
= System
.nanoTime();
234 rs
= stmt
.executeQuery();
238 rs
= stmt
.executeQuery();
241 rs
= stmt
.executeQuery();
249 end
= System
.nanoTime();
255 long val
= tot
/totalrecord
;
256 //System.out.println("Thread id "+this.thid+"Total select "+recordCount+" Avgtime :"+val);
257 System
.out
.println("Total Record select "+recordCount
);
259 }catch(Exception e
) {
260 System
.out
.println("Exception in Test: "+e
+"Thread NO"+thid
);