adding test scripts
[csql.git] / test / jdbc / Gateway / GwTest14.java
blob8e349c067c64d7d3ea03c1acde14a02b07939315
1 //donot run csql server
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 GwTest14 {
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) + " "
54 rs.close();
55 con.commit();
56 con.close();
57 }catch(Exception e) {
58 System.out.println("Exception in Test: "+e);
59 e.printStackTrace();