adding test scripts
[csql.git] / test / jdbc / Connection / ConnTest34.java
blob8ae7829f9c63d0ecd445752cab50ee82f6c4a26f
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 //Author: XieLiang
4 import java.sql.*;
5 public class ConnTest34
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 con.setAutoCommit(true);
14 Statement cStmt = con.createStatement();
15 PreparedStatement stmt = null;
16 int ret = 0;
17 cStmt.execute("CREATE TABLE T1 (f1 integer, f2 char (20));");
18 cStmt.close();
19 for (int i=0; i <10; i++)
21 stmt = con.prepareStatement("INSERT INTO T1 VALUES(?,?);");
22 stmt.setInt(1,i);
23 stmt.setString(2,"test"+i);
24 ret = stmt.executeUpdate();
25 stmt.close();
26 if(ret != 1)
28 System.out.println("test failed");
29 break;
32 con.rollback();
34 int count = 0;
35 cStmt = con.createStatement();
36 ResultSet rs = cStmt.executeQuery("SELECT * from T1;");
37 while(rs.next())
39 count++;
41 rs.close();
42 cStmt.execute("DROP TABLE T1;");
43 cStmt.close();
44 con.close();
45 if (count == 10)
46 System.exit(0);
47 else
48 System.exit(1);
49 }catch(Exception e) {
50 System.out.println("Exception in Test: "+e);
51 e.printStackTrace();
52 System.exit(1);