使用ibatis xml在下面提到了我的原始查询:
数据库记录未更新。
<update>
update
nest set
nstatus = #status#
where
nestid =
#nestId# and (nstatus != #deviceStatus# OR nstatus IS NULL)
</update>
但是下面的查询准备的Java SQL我的日志如下。
DEBUG java.sql.Connection - {conn-100103} Preparing Statement: update nest set nstatus = ? where nestid = ? and nstatus != ? or nstatus = NULL
DEBUG java.sql.PreparedStatement - {pstm-100104} Executing Statement: update nest set nstatus = ? where nestid = ? and nstatus != ? or nstatus = NULL
DEBUG java.sql.PreparedStatement - {pstm-100104} Parameters: [Apple, 150495, Device]
DEBUG java.sql.PreparedStatement - {pstm-100104} Types: [java.lang.String, java.lang.Integer, java.lang.String]
并且我正在使用mysql Db更新记录,它接受以下更新查询。
(= null) is not accepting in mysql while updating records
和(IS NULL) is acceptable to update records
声明应如下所示:
update nest set nstatus = ? where nestid = ? and nstatus != ? or nstatus IS NULL
请告诉我解决方案,我的ibatis更新声明应做哪些更改。
最佳答案
您需要将更新命令重构为
update nest set
nstatus = #status#
where
( nestid = #nestId# AND nstatus != #deviceStatus#)
OR
nstatus IS NULL