2 //CREATE TABLE t1 (f1 integer, f2 smallint, f3 tinyint,f4 bigint, f5 float, f6 char(10), f7 date, f8 time, f9 timestamp);
3 //insert 9 tuples with params for all fields (INSERT INTO t1 values (?,?,?,?,?,?,?,?,?))
4 //select tuple with WHERE clause having param for each fields(SELECT * FROM t1 WHERE f1=?, SELECT * from T1 where f2=?)
10 public class GwStmt4
{
11 public static void main(String
[] args
)
15 Class
.forName("csql.jdbc.JdbcSqlDriver");
16 Connection con
= DriverManager
.getConnection("jdbc:gateway", "root", "manager");
17 Statement cStmt
= con
.createStatement();
18 PreparedStatement stmt
= null, selStmt
= null;
19 stmt
= con
.prepareStatement("INSERT INTO t1 VALUES (?,?,?,?,?,?,?,?);");
21 stmt
.setShort(2,(short)2);
22 //stmt.setByte(3,(byte)3);
23 stmt
.setLong(3,(long)4);
24 stmt
.setFloat(4,(float)5);
25 stmt
.setString(5, String
.valueOf(5));
26 stmt
.setDate(6,Date
.valueOf("2008-03-21"));
27 stmt
.setTime(7,Time
.valueOf("18:00:00"));
28 stmt
.setTimestamp(8,Timestamp
.valueOf("2008-03-21 18:00:00"));
33 selStmt
= con
.prepareStatement("SELECT * from t1 where f1 = ?;");
37 rs
= selStmt
.executeQuery();
40 System
.out
.println("Tuple value is " + rs
.getInt(1) + " "+
44 rs
.getString(5) + " "+
47 rs
.getTimestamp(8) + " "
54 System
.out
.println("Exception in Test: "+e
);