moving server source files to server folder
[csql.git] / test / jdbc / Connection / ConnTest2.java
blob2e40158a1c31c5f29938c89f89a11d8d82c22f0e
1 //Test 5000 connections
2 //Author: XieLiang
3 import java.sql.*;
5 public class ConnTest2
7 public static void main(String[] args)
9 try
11 Class.forName("csql.jdbc.JdbcSqlDriver");
12 Connection con = DriverManager.getConnection("jdbc:csql", "root", "manager");
13 Statement cStmt = con.createStatement();
14 int ret =0;
15 cStmt.execute("CREATE TABLE T1 (f1 integer, f2 char (20));");
16 con.close();
17 int count =0;
18 PreparedStatement stmt = null;
19 for (int i=0; i <5000 ; i++)
21 con = DriverManager.getConnection("jdbc:csql", "root", "manager");
22 con.setAutoCommit(false);
23 stmt = con.prepareStatement("INSERT INTO T1 VALUES (?, ?);");
24 stmt.setInt(1, i);
25 stmt.setString(2, String.valueOf(i+100));
26 ret = stmt.executeUpdate();
27 if (ret != 1) break;
28 count++;
29 stmt.close();
30 con.commit();
31 con.close();
32 if (i%100 ==0) {System.out.println("Total Connections made "+ i); System.gc(); Thread.sleep(500);}
34 System.out.println("Total Rows inserted "+ count);
37 con = DriverManager.getConnection("jdbc:csql", "root", "manager");
38 cStmt = con.createStatement();
39 System.out.println("Listing tuples:");
40 ResultSet rs = cStmt.executeQuery("SELECT * from T1;");
41 count =0;
42 while (rs.next())
44 count++;
46 rs.close();
47 con.commit();
48 System.out.println("Total rows selected " + count);
49 cStmt.execute("DROP TABLE T1;");
50 con.close();
51 if (count !=5000) System.exit(1); else System.exit(0);
52 }catch(Exception e) {
53 System.out.println("Exception in Test: "+e);
54 e.printStackTrace();
55 System.exit(1);