adding test scripts
[csql.git] / test / jdbc / network / Statement / TestScript1.java
blobb99a8e3810c1acb45d24fe3a2af88dfa311b94de
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://localhost:5678", "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 rs=selStmt.executeQuery();
54 while(rs.next())
57 System.out.print("Tuple value is " + rs.getInt(1)+ " ");
58 if(rs.wasNull()) System.out.print(" NULL");
59 System.out.print(rs.getShort(2) + " ");
60 if(rs.wasNull()) System.out.print(" NULL");
61 System.out.print(rs.getByte(3) + " ");
62 if(rs.wasNull()) System.out.print(" NULL");
63 System.out.print(rs.getLong(4) + " ");
64 if(rs.wasNull()) System.out.print(" NULL");
65 System.out.print(rs.getFloat(5) + " ");
66 if(rs.wasNull()) System.out.print(" NULL");
67 System.out.print(rs.getString(6) + " ");
68 if(rs.wasNull()) System.out.print(" NULL");
69 System.out.print(rs.getDate(7) + " ");
70 if(rs.wasNull()) System.out.print(" NULL");
71 System.out.print(rs.getTime(8) + " ");
72 if(rs.wasNull()) System.out.print(" NULL");
73 System.out.println(rs.getTimestamp(9) + " ");
74 if(rs.wasNull()) System.out.println(" NULL");
77 rs.close();
78 con.commit();
79 cStmt.executeUpdate("Drop table T1;");
80 con.close();
81 }catch(Exception e) {
82 System.out.println("Exception in Test: "+e);
83 e.printStackTrace();
84 System.exit(1);