How to check is null in update statement using ibatis?

892 Views Asked by At

My original query is mentioned bellow using ibatis xml: DB records not updating.

<update>
update
        nest set
        nstatus = #status#
        where
        nestid =
        #nestId# and (nstatus != #deviceStatus# OR nstatus IS NULL)
</update>

But java SQL preparing following query my logs are bellow.

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]

and i am using mysql Db to update records it accept the following update query.(= null) is not accepting in mysql while updating records and (IS NULL) is acceptable to update records

statement should be like this:

update   nest set   nstatus = ?   where   nestid =   ? and nstatus != ? or nstatus IS NULL 

Please tell Tell me the sollution, what change should i do in my ibatis update statement.

1

There are 1 best solutions below

0
On

You need to re-factor the the update command something as

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