【问题标题】:How to check is null in update statement using ibatis?如何使用 ibatis 检查更新语句中是否为空?
【发布时间】:2014-11-12 12:36:07
【问题描述】:

下面使用 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 更新声明中做哪些更改。

【问题讨论】:

    标签: mysql spring mybatis ibatis


    【解决方案1】:

    您需要将更新命令重构为

    update nest set
    nstatus = #status#
    where 
    ( nestid = #nestId#  AND nstatus != #deviceStatus#)
    OR
    nstatus IS NULL
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-01
      • 2012-02-14
      • 2017-12-31
      • 2015-07-01
      • 1970-01-01
      • 2011-12-06
      相关资源
      最近更新 更多