1 //update tuple with WHERE clause having param for all fields(UPDATE t1 SET f2=100 WHERE f1=?AND f3=?....)
8 public static void main(String
[] arg
)
12 Class
.forName("csql.jdbc.JdbcSqlDriver");
13 Connection con
=DriverManager
.getConnection("jdbc:gateway","root","manager");
14 Statement cStmt
=con
.createStatement();
15 PreparedStatement stmt
=null,selStmt
=null;
16 stmt
=con
.prepareStatement("INSERT INTO t1 VALUES(?,?,?,?,?,?,?,?);");
21 stmt
.setShort(2,(short)(i
+1));
22 // stmt.setByte(3,(byte)(i+2));
23 stmt
.setLong(3,(long)i
);
24 stmt
.setFloat(4,(float)1000+i
);
25 stmt
.setString(5, String
.valueOf("Cache"+i
));
26 stmt
.setDate(6,Date
.valueOf("2008-03-21"));
27 if(System
.getenv("DSN").equals("oracle"))
28 stmt
.setDate(7,Date
.valueOf("2009-04-24"));
30 stmt
.setTime(7,Time
.valueOf("18:00:00"));
31 stmt
.setTimestamp(8,Timestamp
.valueOf("2008-03-21 18:00:00"));
32 ret
=stmt
.executeUpdate();
37 selStmt
=con
.prepareStatement("Select * from t1");
39 rs
=selStmt
.executeQuery();
42 if(System
.getenv("DSN").equals("oracle")){
43 System
.out
.println("Tuple value is " + rs
.getInt(1) + " "+
47 rs
.getString(5) + " "+
50 rs
.getTimestamp(8) + " "
54 System
.out
.println("Tuple value is " + rs
.getInt(1) + " "+
58 rs
.getString(5) + " "+
61 rs
.getTimestamp(8) + " "
68 stmt
=con
.prepareStatement("UPDATE t1 SET f2=?, f8=? WHERE f1=?AND f9=?;");
71 stmt
.setShort(1,(short)100);
72 if(System
.getenv("DSN").equals("oracle"))
73 stmt
.setDate(2,Date
.valueOf("2009-09-25"));
75 stmt
.setTime(2,Time
.valueOf("19:38:25"));
77 stmt
.setTimestamp(4,Timestamp
.valueOf("2008-03-21 18:00:00"));
78 ret
=stmt
.executeUpdate();
83 selStmt
=con
.prepareStatement("Select * from t1");
85 rs
=selStmt
.executeQuery();
89 if(System
.getenv("DSN").equals("oracle")){
90 System
.out
.println("Tuple value is " + rs
.getInt(1) + " "+
94 rs
.getString(5) + " "+
97 rs
.getTimestamp(8) + " "
101 System
.out
.println("Tuple value is " + rs
.getInt(1) + " "+
102 rs
.getShort(2) + " "+
104 rs
.getFloat(4) + " "+
105 rs
.getString(5) + " "+
108 rs
.getTimestamp(8) + " "
115 }catch(Exception e
) {
116 System
.out
.println("Exception in Test: "+e
);