File Removed
[csql.git] / test / jdbc / Gateway / GwStmt5.java
blob24ec486a41e7f1dd14b96e11be011eab61004b35
1 //Cache table
2 //select tuple with WHERE clause having param for some fields(SELECT * FROM T1 WHERE f1=?AND f2=? AND f3=?)
3 import java.sql.*;
4 /**
6 * @author bijaya
7 */
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(4,(long)i);
25 stmt.setFloat(5,(float)1000+i);
26 stmt.setString(6, String.valueOf("Nihar"+i));
27 stmt.setDate(7,Date.valueOf("2008-03-21"));
28 stmt.setTime(8,Time.valueOf("18:00:00"));
29 stmt.setTimestamp(9,Timestamp.valueOf("2008-03-21 18:00:00"));
30 ret=stmt.executeUpdate();
31 if(ret!=1) break;
33 stmt.close();
34 con.commit();
35 selStmt=con.prepareStatement("SELECT * FROM T1 where f1 = ? ");
36 ResultSet rs=null;
37 selStmt.setInt(1,2);
38 //selStmt.setShort(2,(short)3);
39 //selStmt.setByte(1,(byte)4);
40 rs=selStmt.executeQuery();
41 while(rs.next())
43 System.out.println("Tuple value is " + rs.getInt(1) + " "+
44 rs.getShort(2) + " "+
45 rs.getByte(3) + " "+
46 rs.getLong(4) + " "+
47 rs.getFloat(5) + " "+
48 rs.getString(6) + " "+
49 rs.getDate(7) + " "+
50 rs.getTime(8) + " "+
51 rs.getTimestamp(9) + " "
53 System.out.println("Yes");
55 rs.close();
56 con.commit();
57 con.close();
58 }catch(Exception e) {
59 System.out.println("Exception in Test: "+e);
60 e.printStackTrace();