adding test scripts
[csql.git] / test / jdbc / network / Connection / ConnTest25.java
blobf38e6d78685f3386a444b17f057759fafa6cfb5f
1 //Create connection, set auto-commit false, create Statement, insert 10 tuples, commit the transaction, close connection
2 //Open another connection and check the number of tuples. It should be Ten.
3 import java.sql.*;
4 public class ConnTest25
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.commit();
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 ==10 ) 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);