I am using following datatype in my database .
but I got exception as Exception as:
in thread “Thread-2” java.lang.NumberFormatException: null
How to resolve it
btn.addActionListener(new ActionListener()
{
Thread thread= new Thread()
{
public void run()
{
Connection con= conn.getconnection();
get_data();
String Query = " INSERT INTO employees (Id,
P_F_No,
Name,
Date,
Guard/LP/ALP,
Incomming_Train,
Sign_off,
Room_Bed_No,
Out_going_train_time,
Sign_on,
subisezed_meal)
VALUES
(?,?,?,?,?,?,?,?,?,?,?)";
try
{
PreparedStatement pr = con.prepareStatement(Query);
pr.setString(1,data[0]);
pr.setInt(2,Integer.parseInt(data[1]));
pr.setString(3,data[2]);
pr.setDate(4,Date.valueOf(data[3]));
pr.setString(5,data[4]);
pr.setTime(6,Time.valueOf(data[5]));
pr.setTime(7,Time.valueOf(data[6]));
pr.setString(8,data[7]);
pr.setTime(9,Time.valueOf(data[8]));
pr.setTime(10,Time.valueOf(data[9]));
pr.setString(11,data[10]);
pr.executeUpdate();
}
catch (SQLException ex)
{
System.out.println(ex);
}
}
};
thread.start();
});
You should check if your variable is null and use ‘setNull’ method from
PreparedStatement. For example:Something similar for other types(VARCHAR, etc.). Oracle is trying to convert the value you are passing to the type it is expecting. In your case, you have problems with numbers, but it could happen something similar with String if value is null. For that, you need to indicated that you want to insert a null value as I described above.