1 // Run csqlserver ,Create table. At the time of insertion , Insert some record with Null Value
2 //Check null inserted or not
9 public class TestScript1
{
11 public static void main(String
[] args
) {
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);");
20 PreparedStatement stmt
=null,selStmt
=null;
21 stmt
=con
.prepareStatement("INSERT INTO T1 VALUES(?,?,?,?,?,?,?,?,?);");
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
);
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();
51 selStmt
=con
.prepareStatement("SELECT * FROM T1 ;");
54 selStmt
.setShort(2,(short)3);
55 selStmt
.setByte(3,(byte)4);
56 rs
=selStmt
.executeQuery();
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");
82 cStmt
.executeUpdate("Drop table T1;");
85 System
.out
.println("Exception in Test: "+e
);