为了账号安全,请及时绑定邮箱和手机立即绑定

如何忽略 SQL 更新中的列

如何忽略 SQL 更新中的列

临摹微笑 2021-10-17 11:00:45
我有一个程序可以查看用户模型,如果它们不为空,则将值添加到准备好的更新语句中,如下所示    PreparedStatement pst = conn.prepareStatement("UPDATE users SET name=?,email=?,pwd=?,avatar=?,sts=?,bio=?,country=? WHERE uuid=?");    if(this.name != null) pst.setString(1, this.name);    if(this.email != null) pst.setString(2, this.email);    if(this.password != null) pst.setString(3, this.password);    if(this.avatar != null) pst.setString(4, this.avatar);    if(this.status != null) pst.setString(5, this.status);    if(this.bio != null) pst.setString(6, this.bio);    if(this.country != null) pst.setString(7, this.country);    pst.setString(6, this.id);我面临的问题是准备好的语句中不能有未定义的字段。我可以将不想更改的字段设置为等于什么?
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 99 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信