expected file was wrong.
[csql.git] / test / jdbc / Statement / StmtTest1.java
blob8de367aa69c1652b375d00a812bf699863d9af1b
1 //Test DML statement with parameters
2 import java.sql.*;
3 public class StmtTest1
5 public static void main(String[] args)
7 try
9 Class.forName("csql.jdbc.JdbcSqlDriver");
10 Connection con = DriverManager.getConnection("jdbc:csql", "root", "manager");
11 Statement cStmt = con.createStatement();
12 cStmt.execute("CREATE TABLE T1 (f1 integer, f2 char (20));");
13 cStmt.execute("CREATE INDEX IDX ON T1 ( f1);");
14 con.commit();
15 PreparedStatement stmt = null, selStmt= null;
16 stmt = con.prepareStatement("INSERT INTO T1 VALUES (?, ?);");
17 for (int i =0 ; i< 10 ; i++) {
18 stmt.setInt(1, i);
19 stmt.setString(2, String.valueOf(i+100));
20 stmt.executeUpdate();
22 stmt.close();
23 con.commit();
24 selStmt = con.prepareStatement("SELECT * from T1 where f1 = ?;");
25 ResultSet rs = null;
26 for (int i =0 ; i< 10 ; i++) {
27 selStmt.setInt(1, i);
28 rs = selStmt.executeQuery();
29 while (rs.next())
31 System.out.println("Tuple value is " + rs.getInt(1)+ " "+ rs.getString(2));
33 rs.close();
35 int ret=0;
36 stmt = con.prepareStatement("UPDATE T1 SET f2 = ? WHERE f1 = ?;");
37 for (int i =0 ; i< 10 ; i +=2) {
38 stmt.setString(1, String.valueOf(i+200));
39 stmt.setInt(2, i);
40 ret = stmt.executeUpdate();
41 if (ret != 1) break;
43 stmt.close();
44 con.commit();
46 System.out.println("After update, listing tuples:");
47 for (int i =0 ; i< 10 ; i++) {
48 selStmt.setInt(1, i);
49 rs = selStmt.executeQuery();
50 while (rs.next())
52 System.out.println("Tuple value is " + rs.getInt(1)+ " "+ rs.getString(2));
54 rs.close();
56 con.commit();
60 stmt = con.prepareStatement("DELETE FROM T1 WHERE f1 = ?;");
61 for (int i =0 ; i< 10 ; i +=3) {
62 stmt.setInt(1, i);
63 ret = stmt.executeUpdate();
64 if (ret !=1) break;
66 stmt.close();
67 con.commit();
69 System.out.println("After delete, listing tuples:");
70 for (int i =0 ; i< 10 ; i++) {
71 selStmt.setInt(1, i);
72 rs = selStmt.executeQuery();
73 while (rs.next())
75 System.out.println("Tuple value is " + rs.getInt(1)+ " "+ rs.getString(2));
77 rs.close();
79 con.commit();
80 cStmt.execute("DROP TABLE T1 ;");
81 con.close();
82 }catch(Exception e) {
83 System.out.println("Exception in Test: "+e);
84 e.printStackTrace();