1 //select tuple with WHERE clause having param for some fields(SELECT * FROM T1 WHERE f1=?AND f2=? AND f3=?)
5 public static void main(String
[] arg
)
9 Class
.forName("csql.jdbc.JdbcSqlDriver");
10 Connection con
=DriverManager
.getConnection("jdbc:csql","root","manager");
11 Statement cStmt
=con
.createStatement();
12 cStmt
.execute("CREATE TABLE T1 (f1 integer, f2 smallint, f3 tinyint, f4 bigint, f5 float, f6 char(10), f7 date, f8 time, f9 timestamp);");
14 PreparedStatement stmt
=null,selStmt
=null;
15 stmt
=con
.prepareStatement("INSERT INTO T1 VALUES(?,?,?,?,?,?,?,?,?);");
20 stmt
.setShort(2,(short)(i
+1));
21 stmt
.setByte(3,(byte)(i
+2));
22 stmt
.setLong(4,(long)i
);
23 stmt
.setFloat(5,(float)1000+i
);
24 stmt
.setString(6, String
.valueOf("Nihar"+i
));
25 stmt
.setDate(7,Date
.valueOf("2008-03-21"));
26 stmt
.setTime(8,Time
.valueOf("18:00:00"));
27 stmt
.setTimestamp(9,Timestamp
.valueOf("2008-03-21 18:00:00"));
28 ret
=stmt
.executeUpdate();
33 selStmt
=con
.prepareStatement("SELECT * FROM T1 where f1 = ? and f2 = ? and f3 = ?");
36 selStmt
.setShort(2,(short)3);
37 selStmt
.setByte(3,(byte)4);
38 rs
=selStmt
.executeQuery();
41 System
.out
.println("Tuple value is " + rs
.getInt(1) + " "+
46 rs
.getString(6) + " "+
49 rs
.getTimestamp(9) + " "
55 cStmt
.executeUpdate("Drop table T1;");
58 System
.out
.println("Exception in Test: "+e
);