我正在尝试使用mybatis更新数据库密码:
update person
set name = #{name},
address = #{address},
phoneNumber = #{phoneNumber},
balance = #{balance},
password = #{password},
id = #{new_id}
where id = #{id}
然而,有以下例外:
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'id' cannot be null
### The error may involve com.lsp.mybatis.PersonMapper.update-Inline
### The error occurred while setting parameters
### SQL: update person set name = ?, address = ?, phoneNumber = ? ,balance = ?, password = ?, id = ? where id = ?
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'id' cannot be null
我已指定要更新的用户ID。为什么说“id不能为空”?
有人可以告诉我我做错了吗?
答案 0 :(得分:2)
在查询中删除:id = #{new_id}
。
所以,查询将是:
update person
set name = #{name},
address = #{address},
phoneNumber = #{phoneNumber},
balance = #{balance},
password = #{password}
where id = #{id}