I want to insert in my database lots of data with a Java program. I'm trying to manage the fact that the value of the String could be empty, in that way, I want to set the value to null.
This isn't working (pstm.setFloat...
) :
PreparedStatement pstm;
try {
pstm = connex.prepareStatement("INSERT INTO opfofa._produit_val_nut VALUES (?,?,?,?,?,?,?,?,?,?)");
pstm.setInt(1,id);
pstm.setString(2,tabChaine[8]);
pstm.setFloat(3,tabChaine[9].isEmpty()? null:Float.valueOf(tabChaine[9]));
...
pstm.executeUpdate();
}catch(PSQLException e) {
System.out.println("already inserted : "+e);
}
Error : java.lang.NullPointerException and that is normal because we can't set a float to null but in PostgreSQL I can set a Numeric column to null.
How can I do this?