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
;
13 public class TestScript3
{
14 public static void main(String
[] args
)
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);");
24 PreparedStatement stmt
= null, selStmt
= null;
25 stmt
= con
.prepareStatement("INSERT INTO T1 VALUES (?, ?);");
27 for (int i
=0 ; i
< 10 ; i
++) {
29 stmt
.setString(2, String
.valueOf(i
+100));
30 ret
=stmt
.executeUpdate();
32 System
.out
.println("ExecuteUpdate doesnot return proper values in Insert "+ret
);
35 System
.out
.println("ExecuteUpdate return proper values in Insert ");
39 selStmt
= con
.prepareStatement("SELECT * from T1 where f1 = ?;");
41 for (int i
=0 ; i
< 10 ; i
++) {
43 rs
= selStmt
.executeQuery();
46 System
.out
.println("Tuple value is " + rs
.getInt(1)+ " "+ rs
.getString(2));
51 stmt
= con
.prepareStatement("UPDATE T1 SET f2 = ? WHERE f1 >5;");
53 stmt
.setString(1, String
.valueOf(a
+200));
55 ret
= stmt
.executeUpdate();
57 System
.out
.println("ExecuteUpdate doesnot return proper values for Update "+ret
);
59 System
.out
.println("ExecuteUpdate return proper values fro Update "+ret
);
64 System
.out
.println("After update, listing tuples:");
65 for (int i
=0 ; i
< 10 ; i
++) {
67 rs
= selStmt
.executeQuery();
70 System
.out
.println("Tuple value is " + rs
.getInt(1)+ " "+ rs
.getString(2));
76 stmt
= con
.prepareStatement("DELETE FROM T1 ;");
79 ret
= stmt
.executeUpdate();
82 System
.out
.println("ExecuteUpdate doesnot return proper vslues for Delete "+ret
);
84 System
.out
.println("ExecuteUpdate returns proper vslues for delete "+ret
);
90 cStmt
.execute("DROP TABLE T1 ;");
94 System
.out
.println("Exception in Test: "+e
);