adding test scripts
[csql.git] / test / jdbc / Statement / TestScript1.java
blob305c5b2567d2077e6c0914a65f8b5a46ac9b2185
1 // Run csqlserver ,Create table. At the time of insertion , Insert some record with Null Value
2 //Check null inserted or not
3 // Test For setNull()
4 import java.sql.*;
5 /**
7 * @author bijaya
8 */
9 public class TestScript1 {
11 public static void main(String[] args) {
13 try
15 Class.forName("csql.jdbc.JdbcSqlDriver");
16 Connection con=DriverManager.getConnection("jdbc:csql","root","manager");
17 Statement cStmt=con.createStatement();
18 cStmt.execute("CREATE TABLE T1 (f1 integer, f2 smallint, f3 tinyint, f4 bigint, f5 float, f6 char(10), f7 date, f8 time, f9 timestamp);");
19 con.commit();
20 PreparedStatement stmt=null,selStmt=null;
21 stmt=con.prepareStatement("INSERT INTO T1 VALUES(?,?,?,?,?,?,?,?,?);");
22 int ret=0;
23 for(int i=0;i<10;i++)
25 if(i==2 ) {
26 stmt.setNull(1,java.sql.Types.INTEGER);
27 stmt.setNull(2,java.sql.Types.SMALLINT);
28 stmt.setNull(3,java.sql.Types.TINYINT);
29 stmt.setNull(4,java.sql.Types.BIGINT);
30 stmt.setNull(5,java.sql.Types.FLOAT);
31 stmt.setNull(6,java.sql.Types.CHAR);
32 stmt.setNull(7,java.sql.Types.DATE);
33 stmt.setNull(8,java.sql.Types.TIME);
34 stmt.setNull(9,java.sql.Types.TIMESTAMP);
35 }else{
36 stmt.setInt(1,i);
37 stmt.setShort(2,(short)(i+1));
38 stmt.setByte(3,(byte)(i+2));
39 stmt.setLong(4,(long)i);
40 stmt.setFloat(5,(float)1000+i);
41 stmt.setString(6, String.valueOf("India"+i));
42 stmt.setDate(7,Date.valueOf("2008-03-21"));
43 stmt.setTime(8,Time.valueOf("18:00:00"));
44 stmt.setTimestamp(9,Timestamp.valueOf("2008-03-21 18:00:00"));
46 ret=stmt.executeUpdate();
47 if(ret!=1) break;
49 stmt.close();
50 con.commit();
51 selStmt=con.prepareStatement("SELECT * FROM T1 ;");
52 ResultSet rs=null;
53 selStmt.setInt(1,2);
54 selStmt.setShort(2,(short)3);
55 selStmt.setByte(3,(byte)4);
56 rs=selStmt.executeQuery();
57 while(rs.next())
60 System.out.print("Tuple value is " + rs.getInt(1)+ " ");
61 if(rs.wasNull()) System.out.print(" NULL");
62 System.out.print(rs.getShort(2) + " ");
63 if(rs.wasNull()) System.out.print(" NULL");
64 System.out.print(rs.getByte(3) + " ");
65 if(rs.wasNull()) System.out.print(" NULL");
66 System.out.print(rs.getLong(4) + " ");
67 if(rs.wasNull()) System.out.print(" NULL");
68 System.out.print(rs.getFloat(5) + " ");
69 if(rs.wasNull()) System.out.print(" NULL");
70 System.out.print(rs.getString(6) + " ");
71 if(rs.wasNull()) System.out.print(" NULL");
72 System.out.print(rs.getDate(7) + " ");
73 if(rs.wasNull()) System.out.print(" NULL");
74 System.out.print(rs.getTime(8) + " ");
75 if(rs.wasNull()) System.out.print(" NULL");
76 System.out.println(rs.getTimestamp(9) + " ");
77 if(rs.wasNull()) System.out.println(" NULL");
80 rs.close();
81 con.commit();
82 cStmt.executeUpdate("Drop table T1;");
83 con.close();
84 }catch(Exception e) {
85 System.out.println("Exception in Test: "+e);
86 e.printStackTrace();
87 System.exit(1);