I am trying to insert a null value into an Integer Mysql column using java JDBC driver.
Connection con;
con = MySqlConnect.getConnection(accountName);
con.setAutoCommit(false);
PreparedStatement stmt = con.prepareStatement("INSERT INTO TABLE_NAME (COLUMN_NAME) VALUES (?)");
stmt.setNull(1, Types.INTEGER);
stmt.addBatch();
stmt.executeBatch();
But I am getting this error :
java.sql.BatchUpdateException: Incorrect integer value: '' for column 'COLUMN_NAME' at row 1
I don't understand why I can't insert this value (also why it is written '' instead of null). Schema of the table is including
COLUMN_NAMEint(10) DEFAULT NULL,
If reproduce an alternate scenario using Float data type :
FLOAT_COLUMNfloat(10) DEFAULT NULL,
And chaning the setNull line to :
stmt.setNull(1, Types.FLOAT);
It works (so for the float data type not int).