adding test scripts
[csql.git] / test / sqlnetwork / Jdbcnetwork / StmtTest6.java
blobfcbadca1f1412c692131cce04940896fa87e19df
1 //select tuple with WHERE clause having param for some fields(SELECT * FROM T1 WHERE f1=?AND f2=? AND f3=?)
2 import java.sql.*;
3 public class StmtTest6
5 public static void main(String[] arg)
7 try
9 Class.forName("csql.jdbc.JdbcSqlDriver");
10 Connection con=DriverManager.getConnection("jdbc:csql://localhost:5678/csql","root","manager");
11 Statement cStmt=con.createStatement();
12 cStmt.execute("CREATE TABLE T1 (f1 integer, f2 smallint, f3 tinyint, f4 bigint, f5 float, f6 char(10), f7 date, f8 time, f9 timestamp);");
13 con.commit();
14 PreparedStatement stmt=null,selStmt=null;
15 stmt=con.prepareStatement("INSERT INTO T1 VALUES(?,?,?,?,?,?,?,?,?);");
16 int ret=0;
17 for(int i=0;i<10;i++)
19 stmt.setInt(1,i);
20 stmt.setShort(2,(short)(i+1));
21 stmt.setByte(3,(byte)(i+2));
22 stmt.setLong(4,(long)i);
23 stmt.setFloat(5,(float)1000+i);
24 stmt.setString(6, String.valueOf("Nihar"+i));
25 stmt.setDate(7,Date.valueOf("2008-03-21"));
26 stmt.setTime(8,Time.valueOf("18:00:00"));
27 stmt.setTimestamp(9,Timestamp.valueOf("2008-03-21 18:00:00"));
28 ret=stmt.executeUpdate();
29 if(ret!=1) break;
31 stmt.close();
32 con.commit();
33 selStmt=con.prepareStatement("SELECT * FROM T1 where f1 = ? and f2 = ? and f3 = ?");
34 ResultSet rs=null;
35 selStmt.setInt(1,2);
36 selStmt.setShort(2,(short)3);
37 selStmt.setByte(3,(byte)4);
38 rs=selStmt.executeQuery();
39 while(rs.next())
41 System.out.println("Tuple value is " + rs.getInt(1) + " "+
42 rs.getShort(2) + " "+
43 rs.getByte(3) + " "+
44 rs.getLong(4) + " "+
45 rs.getFloat(5) + " "+
46 rs.getString(6) + " "+
47 rs.getDate(7) + " "+
48 rs.getTime(8) + " "+
49 rs.getTimestamp(9) + " "
53 rs.close();
54 con.commit();
55 cStmt.executeUpdate("Drop table T1;");
56 con.close();
57 }catch(Exception e) {
58 System.out.println("Exception in Test: "+e);
59 e.printStackTrace();