adding test scripts
[csql.git] / test / jdbc / Gateway / GwStmt4.java
blob7d959890ba5f76747a38edf9a258c88d2b95b0fa
1 //Chache table t1
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=?)
5 import java.sql.*;
6 /**
8 * @author bijaya
9 */
10 public class GwStmt4 {
11 public static void main(String[] args)
13 try
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 (?,?,?,?,?,?,?,?);");
20 stmt.setInt(1, 1);
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"));
29 stmt.executeUpdate();
30 stmt.close();
31 con.commit();
33 selStmt = con.prepareStatement("SELECT * from t1 where f1 = ?;");
34 ResultSet rs = null;
36 selStmt.setInt(1, 1);
37 rs = selStmt.executeQuery();
38 while (rs.next())
40 System.out.println("Tuple value is " + rs.getInt(1) + " "+
41 rs.getShort(2) + " "+
42 rs.getLong(3) + " "+
43 rs.getFloat(4) + " "+
44 rs.getString(5) + " "+
45 rs.getDate(6) + " "+
46 rs.getTime(7) + " "+
47 rs.getTimestamp(8) + " "
50 rs.close();
51 selStmt.close();
52 con.close();
53 }catch(Exception e) {
54 System.out.println("Exception in Test: "+e);
55 e.printStackTrace();