adding test scripts
[csql.git] / test / jdbc / Gateway / GwStmt2.java
blob9f2d04724caf74bea6479477493d6a907bde81fc
1 //Cache table t1
2 //Create a table and index for that table. Then do (INSERT/UPDATE/DELETE/SELECT) with no params statement.
3 import java.sql.*;
4 /**
6 * @author bijaya
7 */
8 public class GwStmt2 {
9 public static void main(String[] args)
11 try
13 Class.forName("csql.jdbc.JdbcSqlDriver");
14 Connection con = DriverManager.getConnection("jdbc:gateway", "root", "manager");
15 Statement cStmt = con.createStatement();
16 con.commit();
18 cStmt.execute("INSERT INTO t1 VALUES (1, 'FIRST');");
19 cStmt.executeUpdate("INSERT INTO t1 VALUES (2, 'SECOND');");
20 con.commit();
22 ResultSet rs = null;
23 rs = cStmt.executeQuery("SELECT * from t1 where f1 = 1;");
24 while (rs.next())
26 System.out.println("Tuple value is " + rs.getInt(1)+ " "+ rs.getString(2));
28 rs.close();
31 cStmt.execute("SELECT * from t1 where f1 = 2;");
32 rs = cStmt.getResultSet();
33 while (rs.next())
35 System.out.println("Tuple value is " + rs.getInt(1)+ " "+ rs.getString(2));
37 rs.close();
38 con.commit();
40 cStmt.executeUpdate("UPDATE t1 SET f2 = 'CHANGED' WHERE f1 = 1;");
41 con.commit();
45 cStmt.executeUpdate("DELETE FROM t1 WHERE f1 = 2;");
46 con.commit();
48 System.out.println("After delete, listing tuples:");
49 rs = cStmt.executeQuery("SELECT * from t1 ;");
50 while (rs.next())
52 System.out.println("Tuple value is " + rs.getInt(1)+ " "+ rs.getString(2));
54 rs.close();
55 con.close();
56 }catch(Exception e) {
57 System.out.println("Exception in Test: "+e);
58 e.printStackTrace();