adding test scripts
[csql.git] / test / jdbc / Gateway / GwTest13.java
blob8e694862ec4eff3b4324b3b0064bc12cf5845de6
1 //donot run csql server
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 GwTest13 {
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(4,(long)4);
24 stmt.setFloat(5,(float)5);
25 stmt.setString(6, String.valueOf(5));
26 stmt.setDate(7,Date.valueOf("2008-03-21"));
27 stmt.setTime(8,Time.valueOf("18:00:00"));
28 stmt.setTimestamp(9,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.getByte(3) + " "+
43 rs.getLong(4) + " "+
44 rs.getFloat(5) + " "+
45 rs.getString(6) + " "+
46 rs.getDate(7) + " "+
47 rs.getTime(8) + " "+
48 rs.getTimestamp(9) + " "
51 rs.close();
52 selStmt.close();
53 con.close();
54 }catch(Exception e) {
55 System.out.println("Exception in Test: "+e);
56 e.printStackTrace();