Return number of rows affected by SQL UPDATE statement in Java

后端 未结 7 1961
花落未央
花落未央 2020-12-30 20:26

I\'m using a MySQL database and accessing it through Java.

PreparedStatement prep1 = this.connection.prepareStatement(
        \"UPDATE user_table 
                


        
7条回答
  •  感动是毒
    2020-12-30 20:35

    Looking at this just now for another similar situation, where I only want to do additional work if something really changed, I think the most platform neutral way to do it would be to alter the query to exclude the case where the set fields match:

    UPDATE user_table SET Level = 'Super' WHERE Username = ? AND Level <> 'Super'
    

提交回复
热议问题