簡體   English   中英

java.sql.BatchUpdateException: Incorrect integer value: '' for column '' at row 1 when setting value to null

[英]java.sql.BatchUpdateException: Incorrect integer value: '' for column '' at row 1 when setting value to null

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();

但我收到此錯誤:

java.sql.BatchUpdateException:不正確的 integer 值:第 1 行的列“COLUMN_NAME”的“”

我不明白為什么我不能插入這個值(也是為什么它寫成 '' 而不是 null)。 表的架構包括

COLUMN_NAME int(10) 默認 NULL,

如果使用 Float 數據類型重現替代方案:

FLOAT_COLUMN float(10) 默認 NULL,

並將 setNull 行更改為:

stmt.setNull(1, Types.FLOAT);

它有效(因此對於浮點數據類型不是 int)。

你試試: stmt.setNull(paramIndex, Types.BIGINT); ?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM