Hello friends,
This requires some imeediate help.
Im working with inserting null values thru PreparedStatements. I want to set a Date field to null.The field is designed to accept null values.Any manual inserts doesnt give me problems but then when i try to insert null for this field through a PreparedStatement it gives me a NullPointerException or a Data Out of range
I have tried using setObject() method as well as setNull method.I waork with sqlserver7.0. i have tried this on ms acess also.
given below is the code
//******************************************************************
import java.sql.*;
public class Ins
{
public static void main(
String a[])
{Connection con = null,con2=null;
PreparedStatement st= null;
int i=0;
String cust=" ";
Date d=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc
dbc:NWind");
st=con.prepareStatement("Insert into Employees(LastName,FirstName,BirthDate) values(?,?,?)");
st.setString(1,"gaurav");
st.setString(2,"srivastava");
st.setObject(3,null,Types.DATE);
st.setNull(3,Types.DATE);
i=st.executeUpdate();
con.close();
System.out.println("Insert Success"+i+ " ");
}
catch(Exception e)
{
System.out.println(e);
}
}
}
//******************************************************************
PLEASE HELP ME AS THE SOLUTION IS REQUIRED AS SOON AS POSSIBLE.
THANKS A LOT FOR THE HELP