update会餐出错误

lilinew 2009-09-07 12:32:59
update test.addressbook_table set phone=? and address=? where name=?");
con.setAutoCommit(false);

pStmt.setString(1,phone);
pStmt.setString(2,address);
pStmt.setString(3,name);
int j=pStmt.executeUpdate();
con.commit()
很奇怪,这里phone的值不是按照制定值更新,执行操作完总是为1.
(构造涵数
public AddressBookBean(String name,String phone,String address) {
this.name=name;
this.phone=phone;
this.address=address;
//this.id=id;
}
)

如果是插入 删除都是没有问题的,为什么update会餐出错误?
...全文
112 9 打赏 收藏 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
lilinew 2009-09-07
  • 打赏
  • 举报
回复
感谢yanliang_xt. 一个小的错误...
lilinew 2009-09-07
  • 打赏
  • 举报
回复
未传入之前phone的值是 非1值 如118等
执行完是1 .
插入没这问题,插入与构造的参数次序是一致的
但是更新的次序有很大的变化
yanliang_xt 2009-09-07
  • 打赏
  • 举报
回复

update test.addressbook_table set phone=? , address=? where name=?");

luxiaoshuai 2009-09-07
  • 打赏
  • 举报
回复
你用debug运行.在这里打一个断点...

pStmt.setString(1,phone);

看看在未传入之前phone的值是什么?
gesanri 2009-09-07
  • 打赏
  • 举报
回复
那只能说 pStmt.setString(1,phone);这里的phone你就是赋值的1
zhoujingxian 2009-09-07
  • 打赏
  • 举报
回复
你这问题描述也不是太清楚啊,

执行操作完总是为1,是指j的值为1吧

如果操作正确,你数据库只有一条符合记录,那就是1,没错啊
huangqibing0626 2009-09-07
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 yanliang_xt 的回复:]
SQL codeupdate test.addressbook_tableset phone=? , address=?where name=?");
[/Quote]


呵呵···
zhuyang7654321 2009-09-07
  • 打赏
  • 举报
回复
不明白
closewbq 2009-09-07
  • 打赏
  • 举报
回复
update的时候还用and干什么

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧