*** empty log message ***
[csql.git] / test / jdbc / Statement / TestScript3.java
blob19f0e1b1ae055db8bdd1bc44a296e4d716c687e1
1 //ExecuteUpdate Should return no of records updated
3 import java.sql.Connection;
4 import java.sql.DriverManager;
5 import java.sql.PreparedStatement;
6 import java.sql.ResultSet;
7 import java.sql.Statement;
9 /**
11 * @author bijaya
13 public class TestScript3 {
14 public static void main(String[] args)
16 try
18 Class.forName("csql.jdbc.JdbcSqlDriver");
19 Connection con = DriverManager.getConnection("jdbc:csql", "root", "manager");
20 Statement cStmt = con.createStatement();
21 cStmt.execute("CREATE TABLE T1 (f1 integer, f2 char (20));");
22 cStmt.execute("CREATE INDEX IDX ON T1 ( f1);");
23 con.commit();
24 PreparedStatement stmt = null, selStmt= null;
25 stmt = con.prepareStatement("INSERT INTO T1 VALUES (?, ?);");
26 int ret=0;
27 for (int i =0 ; i< 10 ; i++) {
28 stmt.setInt(1, i);
29 stmt.setString(2, String.valueOf(i+100));
30 ret=stmt.executeUpdate();
31 if (ret != 1){
32 System.out.println("ExecuteUpdate doesnot return proper values in Insert "+ret);
33 break;
35 System.out.println("ExecuteUpdate return proper values in Insert ");
37 stmt.close();
38 con.commit();
39 selStmt = con.prepareStatement("SELECT * from T1 where f1 = ?;");
40 ResultSet rs = null;
41 for (int i =0 ; i< 10 ; i++) {
42 selStmt.setInt(1, i);
43 rs = selStmt.executeQuery();
44 while (rs.next())
46 System.out.println("Tuple value is " + rs.getInt(1)+ " "+ rs.getString(2));
48 rs.close();
50 int a=5;
51 stmt = con.prepareStatement("UPDATE T1 SET f2 = ? WHERE f1 >5;");
53 stmt.setString(1, String.valueOf(a+200));
55 ret = stmt.executeUpdate();
56 if (ret != 4){
57 System.out.println("ExecuteUpdate doesnot return proper values for Update "+ret);
59 System.out.println("ExecuteUpdate return proper values fro Update "+ret);
61 stmt.close();
62 con.commit();
64 System.out.println("After update, listing tuples:");
65 for (int i =0 ; i< 10 ; i++) {
66 selStmt.setInt(1, i);
67 rs = selStmt.executeQuery();
68 while (rs.next())
70 System.out.println("Tuple value is " + rs.getInt(1)+ " "+ rs.getString(2));
72 rs.close();
74 con.commit();
76 stmt = con.prepareStatement("DELETE FROM T1 ;");
79 ret = stmt.executeUpdate();
80 if (ret !=10)
82 System.out.println("ExecuteUpdate doesnot return proper vslues for Delete "+ret);
84 System.out.println("ExecuteUpdate returns proper vslues for delete "+ret);
86 stmt.close();
87 con.commit();
90 cStmt.execute("DROP TABLE T1 ;");
91 con.close();
92 }catch(Exception e) {
94 System.out.println("Exception in Test: "+e);
95 e.printStackTrace();