我正在尝试使用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不能为空”?
有人能告诉我我做错了什么吗?
最佳答案
在查询中删除:id = #{new_id}
。
因此,问题是:
update person
set name = #{name},
address = #{address},
phoneNumber = #{phoneNumber},
balance = #{balance},
password = #{password}
where id = #{id}
关于java - MySQL更新用户密码,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20154830/