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