adding test scripts
[csql.git] / test / jdbc / network / Connection / ConnTest34.java
blob2347995222d1da1beb957fcfb282b150d8454554
1 //Create Connection, setAutocommit(true), create table t1, insert into t1 10 records
2 //then call rollback(), select and count the number of records. It should be 10
3 import java.sql.*;
4 public class ConnTest34
6 public static void main(String[] args)
8 try
10 Class.forName("csql.jdbc.JdbcSqlDriver");
11 Connection con = DriverManager.getConnection("jdbc:csql://localhost:5678", "root", "manager");
12 con.setAutoCommit(true);
13 Statement cStmt = con.createStatement();
14 PreparedStatement stmt = null;
15 int ret = 0;
16 cStmt.execute("CREATE TABLE T1 (f1 integer, f2 char (20));");
17 cStmt.close();
18 for (int i=0; i <10; i++)
20 stmt = con.prepareStatement("INSERT INTO T1 VALUES(?,?);");
21 stmt.setInt(1,i);
22 stmt.setString(2,"test"+i);
23 ret = stmt.executeUpdate();
24 stmt.close();
25 if(ret != 1)
27 System.out.println("test failed");
28 break;
31 con.rollback();
33 int count = 0;
34 cStmt = con.createStatement();
35 ResultSet rs = cStmt.executeQuery("SELECT * from T1;");
36 while(rs.next())
38 count++;
40 rs.close();
41 cStmt.execute("DROP TABLE T1;");
42 cStmt.close();
43 con.close();
44 if (count == 10)
45 System.exit(0);
46 else
47 System.exit(1);
48 }catch(Exception e) {
49 System.out.println("Exception in Test: "+e);
50 e.printStackTrace();
51 System.exit(1);