adding test scripts
[csql.git] / test / jdbc / network / Statement / StmtTest7.java
blob0193e24660d7404e4d6e2fdb228846efa80df854
1 //update tuple with SET and WHERE clause having params (UPDATE T1 SET f2=?, f8=? WHERE f1=?AND f9=?)
2 import java.sql.*;
3 public class StmtTest7
5 public static void main(String[] arg)
7 try
9 Class.forName("csql.jdbc.JdbcSqlDriver");
10 Connection con = DriverManager.getConnection("jdbc:csql://localhost:5678", "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");
34 ResultSet rs=null;
35 rs=selStmt.executeQuery();
36 while(rs.next())
38 System.out.println("Tuple value is " + rs.getInt(1) + " "+
39 rs.getShort(2) + " "+
40 rs.getByte(3) + " "+
41 rs.getLong(4) + " "+
42 rs.getFloat(5) + " "+
43 rs.getString(6) + " "+
44 rs.getDate(7) + " "+
45 rs.getTime(8) + " "+
46 rs.getTimestamp(9) + " "
50 rs.close();
51 con.commit();
52 ret=0;
53 stmt=con.prepareStatement("UPDATE T1 SET f2=?, f8=? WHERE f1=?AND f9=?;");
54 for(int i=0;i<10;i++)
56 stmt.setShort(1,(short)100);
57 stmt.setTime(2,Time.valueOf("19:38:25"));
58 stmt.setInt(3,3);
59 stmt.setTimestamp(4,Timestamp.valueOf("2008-03-21 18:00:00"));
60 ret=stmt.executeUpdate();
61 if(ret!=1) break;
63 stmt.close();
64 con.commit();
65 selStmt=con.prepareStatement("Select * from T1");
66 rs=null;
67 rs=selStmt.executeQuery();
68 System.out.println();
69 while(rs.next())
71 System.out.println("Tuple value is " + rs.getInt(1) + " "+
72 rs.getShort(2) + " "+
73 rs.getByte(3) + " "+
74 rs.getLong(4) + " "+
75 rs.getFloat(5) + " "+
76 rs.getString(6) + " "+
77 rs.getDate(7) + " "+
78 rs.getTime(8) + " "+
79 rs.getTimestamp(9) + " "
83 rs.close();
84 con.commit();
85 cStmt.executeUpdate("Drop table T1;");
86 con.close();
87 }catch(Exception e) {
88 System.out.println("Exception in Test: "+e);
89 e.printStackTrace();