adding test scripts
[csql.git] / test / jdbc / Connection / ConnTest22.java
blob3418a01bed67a41ac3b431f103f285458f893db4
1 //Create connection, setAutocommit(false) , create Statement, insert 10 tuples, close the connection.
2 //Open another connection and check the number of tuples. It should be Zero.
3 //Author: XieLiang
4 import java.sql.*;
5 public class ConnTest22
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(false);
14 Statement cStmt = con.createStatement();
16 int ret = 0;
17 cStmt.execute("CREATE TABLE T1 (f1 integer, f2 char (20));");
18 PreparedStatement stmt = null;
19 stmt = con.prepareStatement("INSERT INTO T1 VALUES (?, ?);");
20 for (int i=0; i <10 ; i++)
22 stmt.setInt(1, i);
23 stmt.setString(2, String.valueOf(i));
24 ret = stmt.executeUpdate();
25 if (ret !=1) break;
27 stmt.close();
28 con.close();
29 con = DriverManager.getConnection("jdbc:csql","root","manager");
30 int count = 0;
31 cStmt = con.createStatement();
32 ResultSet rs = cStmt.executeQuery("SELECT * from T1;");
33 while(rs.next())
35 count++;
37 rs.close();
38 cStmt.execute("DROP TABLE T1;");
39 con.close();
40 if (count == 0) System.exit(0); else System.exit(1);
41 }catch(Exception e) {
42 System.out.println("Exception in Test: "+e);
43 e.printStackTrace();
44 System.exit(1);