adding test scripts
[csql.git] / test / jdbc / Gateway / GwStmt5.java
blob9733213a086f32c4f383c5bb7f17f35fcc0c56e3
1 //Cache table
2 //select tuple with WHERE clause having param for some fields(SELECT * FROM t1 WHERE f1=?AND f2=? AND f3=?)
3 /**
5 * @author bijaya
6 */
7 import java.sql.*;
8 public class GwStmt5 {
9 public static void main(String[] arg)
11 try
13 Class.forName("csql.jdbc.JdbcSqlDriver");
14 Connection con=DriverManager.getConnection("jdbc:gateway","root","manager");
15 Statement cStmt=con.createStatement();
16 PreparedStatement stmt=null,selStmt=null;
17 stmt=con.prepareStatement("INSERT INTO t1 VALUES(?,?,?,?,?,?,?,?);");
18 int ret=0;
19 for(int i=0;i<10;i++)
21 stmt.setInt(1,i);
22 stmt.setShort(2,(short)(i+1));
23 // stmt.setByte(3,(byte)(i+2));
24 stmt.setLong(3,(long)i);
25 stmt.setFloat(4,(float)1000+i);
26 stmt.setString(5, String.valueOf("Nihar"+i));
27 stmt.setDate(6,Date.valueOf("2008-03-21"));
28 if(System.getenv("DSN").equals("oracle"))
29 stmt.setDate(7,Date.valueOf("2009-04-22"));
30 else
31 stmt.setTime(7,Time.valueOf("18:00:00"));
32 stmt.setTimestamp(8,Timestamp.valueOf("2008-03-21 18:00:00"));
33 ret=stmt.executeUpdate();
34 if(ret!=1) break;
36 stmt.close();
37 con.commit();
38 selStmt=con.prepareStatement("SELECT * FROM t1 where f1 = ? ");
39 ResultSet rs=null;
40 selStmt.setInt(1,2);
41 //selStmt.setShort(2,(short)3);
42 //selStmt.setByte(1,(byte)4);
43 rs=selStmt.executeQuery();
44 while(rs.next())
46 if(System.getenv("DSN").equals("oracle")){
47 System.out.println("Tuple value is " + rs.getInt(1) + " "+
48 rs.getShort(2) + " "+
49 rs.getLong(3) + " "+
50 rs.getFloat(4) + " "+
51 rs.getString(5) + " "+
52 rs.getDate(6) + " "+
53 rs.getDate(7) + " "+
54 rs.getTimestamp(8) + " "
57 else{
58 System.out.println("Tuple value is " + rs.getInt(1) + " "+
59 rs.getShort(2) + " "+
60 rs.getLong(3) + " "+
61 rs.getFloat(4) + " "+
62 rs.getString(5) + " "+
63 rs.getDate(6) + " "+
64 rs.getTime(7) + " "+
65 rs.getTimestamp(8) + " "
68 System.out.println("Yes");
70 rs.close();
71 con.commit();
72 con.close();
73 }catch(Exception e) {
74 System.out.println("Exception in Test: "+e);
75 e.printStackTrace();