adding test scripts
[csql.git] / test / jdbc / Statement / InnerJoinPara.java
blob925fbc9a75b3bde7a5586beec238dc2dcec5bb25
1 //select tuple with WHERE clause having param for some fields in Inner Join(SELECT T1.f1,T2.f1,T1.f2,T2.f2,T1.f3,T2.f3 FROM T1 INNER JOIN T2 ON T1.f1>=2 AND T1.f2>=4 AND T2.f3=6)
2 import java.sql.*;
3 public class InnerJoinPara
5 public static void main(String[] arg)
7 try
9 Class.forName("csql.jdbc.JdbcSqlDriver");
10 Connection con=DriverManager.getConnection("jdbc: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 cStmt.execute("CREATE TABLE T2 (f1 integer, f2 smallint, f3 tinyint, f4 bigint, f5 float, f6 char(10), f7 date, f8 time, f9 timestamp);");
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 System.out.println("SELECT * FROM T1;");
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();
53 stmt=con.prepareStatement("INSERT INTO T2 VALUES(?,?,?,?,?,?,?,?,?);");
54 ret=0;
55 for(int i=0;i<10;i+=2)
57 stmt.setInt(1,i);
58 stmt.setShort(2,(short)(i+1));
59 stmt.setByte(3,(byte)(i+2));
60 stmt.setLong(4,(long)i);
61 stmt.setFloat(5,(float)1000+i);
62 stmt.setString(6, String.valueOf("Nihar"+i));
63 stmt.setDate(7,Date.valueOf("2008-03-21"));
64 stmt.setTime(8,Time.valueOf("18:00:00"));
65 stmt.setTimestamp(9,Timestamp.valueOf("2008-03-21 18:00:00"));
66 ret=stmt.executeUpdate();
67 if(ret!=1) break;
69 stmt.close();
71 System.out.println("SELECT * FROM T2;");
72 selStmt=con.prepareStatement("SELECT * FROM T2;");
73 rs=null;
74 rs=selStmt.executeQuery();
75 while(rs.next())
77 System.out.println("Tuple value is " + rs.getInt(1) + " "+
78 rs.getShort(2) + " "+
79 rs.getByte(3) + " "+
80 rs.getLong(4) + " "+
81 rs.getFloat(5) + " "+
82 rs.getString(6) + " "+
83 rs.getDate(7) + " "+
84 rs.getTime(8) + " "+
85 rs.getTimestamp(9) + " "
89 rs.close();
90 con.commit();
92 System.out.println("SELECT T1.f1,T2.f1,T1.f2,T2.f2,T1.f3,T2.f3 FROM T1 INNER JOIN T2 ON T1.f1>=2 AND T1.f2>=4 AND T2.f3=6");
93 selStmt=con.prepareStatement("SELECT T1.f1,T2.f1,T1.f2,T2.f2,T1.f3,T2.f3 FROM T1 INNER JOIN T2 ON T1.f1>=? AND T1.f2>=? AND T2.f3=?");
94 rs=null;
95 selStmt.setInt(1,2);
96 selStmt.setShort(2,(short)4);
97 selStmt.setByte(3,(byte)6);
98 rs=selStmt.executeQuery();
99 System.out.println("T1.f1\tT2.f1\tT1.f2\tT2.f2\tT1.f3\tT2.f3");
100 while(rs.next())
102 System.out.println( rs.getInt(1) + "\t"+
103 rs.getInt(2) + "\t"+
104 rs.getShort(3) + "\t"+
105 rs.getShort(4) + "\t"+
106 rs.getByte(5) + "\t"+
107 rs.getByte(6)
111 rs.close();
112 con.commit();
114 cStmt.executeUpdate("Drop table T1;");
115 cStmt.executeUpdate("Drop table T2;");
116 con.close();
117 }catch(Exception e) {
118 System.out.println("Exception in Test: "+e);
119 e.printStackTrace();