【发布时间】:2019-04-18 10:24:09
【问题描述】:
PreparedStatement setString 采用“null”(就像 String a = "null"),在 .addBatch 之后它被转换为正常的 null(就像 String a = null 一样)。
我不知道如何能够绕过这种误解,因为很多行在全部添加为批处理之后会立即执行...(sql语句是INSERT INTO...)( VarChar 不能为空,但 String a = "null" 可以被表接受,如果它没有批量发送......整个程序由于来自服务器的错误消息而停止)
错误信息: 将数据写入数据库时出错... org.netezza.error.NzSQLException:错误:第 17 列:字段不能包含空值
代码:
preparedStatement.setString(17, x); //currently x was recieved as "null"
preparedStatement.addBatch() //after other parameters were filled then this statement
preparedStatement.executeBatch(); //after the logs this statement is executed.
希望有一个快速解决方案
我使用了这种绕过方法,但认为可能有更好的方法......(因为我无法更改数据库默认值或操作数据......)
if(helper.toLowerCase().equals("null"))
helper = (helper.equals("null") ? "null ":"NULL ");
preparedStatement.setString(17, helper);
【问题讨论】:
标签: java jdbc prepared-statement netezza