1 /* 1. Table t1 is cached to csql.
2 * 2. Then do (INSERT/UPDATE/DELETE/SELECT) with params statement using gate* way statement
4 * Author : JItendra Lenka
8 import java
.sql
.Connection
;
9 import java
.sql
.DriverManager
;
10 import java
.sql
.PreparedStatement
;
11 import java
.sql
.ResultSet
;
12 import java
.sql
.Statement
;
15 public class AdStmt1
{
16 public static void main(String
[] args
)
20 Class
.forName("csql.jdbc.JdbcSqlDriver");
21 Connection con
= DriverManager
.getConnection("jdbc:adapter", "root", "manager");
22 Statement cStmt
= con
.createStatement();
23 PreparedStatement stmt
= null, selStmt
= null;
24 stmt
= con
.prepareStatement("INSERT INTO t1 VALUES (?, ?);");
25 for (int i
=0 ; i
< 10 ; i
++) {
27 stmt
.setString(2, String
.valueOf(i
+100));
32 selStmt
= con
.prepareStatement("SELECT * from t1 where f1 = ?;");
34 for (int i
=0 ; i
< 10 ; i
++) {
36 rs
= selStmt
.executeQuery();
39 System
.out
.println("Tuple value is " + rs
.getInt(1)+ " "+ rs
.getString(2));
44 stmt
= con
.prepareStatement("UPDATE t1 SET f2 = ? WHERE f1 = ?;");
45 for (int i
=0 ; i
< 10 ; i
+=2) {
46 stmt
.setString(1, String
.valueOf(i
+200));
48 ret
= stmt
.executeUpdate();
53 System
.out
.println("After update, listing tuples:");
54 for (int i
=0 ; i
< 10 ; i
++) {
56 rs
= selStmt
.executeQuery();
59 System
.out
.println("Tuple value is " + rs
.getInt(1)+ " "+ rs
.getString(2));
64 stmt
= con
.prepareStatement("DELETE FROM t1 WHERE f1 = ?;");
65 for (int i
=0 ; i
< 10 ; i
+=3) {
67 ret
= stmt
.executeUpdate();
73 System
.out
.println("After delete, listing tuples:");
74 for (int i
=0 ; i
< 10 ; i
++) {
76 rs
= selStmt
.executeQuery();
79 System
.out
.println("Tuple value is " + rs
.getInt(1)+ " "+ rs
.getString(2));
86 System
.out
.println("Exception in Test: "+e
);