adding test scripts
[csql.git] / test / jdbc / network / Connection / IsoTest2.java
blobc2648a41191c8328299f01656d268c5d2de43e8b
1 //Open two connections and call setTransactionIsolation(TRANSACTION_UNCOMMITTED ).
2 //From 1st connection insert tuple and then sleep, from 2nd connection try to select the inserted tuple.
3 //Tuple should be seen.
4 import java.sql.*;
5 public class IsoTest2
7 public static void main(String[] args)
9 try
11 Class.forName("csql.jdbc.JdbcSqlDriver");
12 Connection con1 = DriverManager.getConnection("jdbc:csql://localhost:5678", "root", "manager");
13 Connection con2 = DriverManager.getConnection("jdbc:csql://localhost:5678", "root", "manager");
14 if ( (con1 == null) || (con2 == null) )
15 System.out.println("test failed!");
16 con1.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
17 con2.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
18 con1.setAutoCommit(false);
19 con2.setAutoCommit(false);
20 Statement cStmt = con1.createStatement();
21 cStmt.execute("CREATE TABLE T1(f1 integer,f2 char(20));");
22 PreparedStatement stmt = null;
23 stmt = con1.prepareStatement("INSERT INTO T1 VALUES(?,?);");
24 stmt.setInt(1,1);
25 stmt.setString(2,"test");
26 int ret = 0;
27 ret = stmt.executeUpdate();
28 if (ret != 1) {
29 con1.close();
30 con2.close();
31 System.exit(1);
34 cStmt = con2.createStatement();
35 ResultSet rs = cStmt.executeQuery("SELECT * FROM T1;");
36 int count =0;
37 while(rs.next())
39 count++;
41 rs.close();
42 cStmt.execute("DROP TABLE T1;");
43 con1.close();
44 con2.close();
45 if (count !=1) System.exit(1); else System.exit(0);
46 }catch(Exception e) {
47 System.out.println(e.getMessage());
48 e.getStackTrace();
49 System.exit(1);