String sql = "update books set bookName='" + bookName + "',ISBN='"
+ ISBN + "',publisher='" + publisher + "',author='" + author
+ "' where id="+id;--------------------------------------------------------------------------------------------------------------
以上代码 出去id外 其他全是字符string类型的字段 如果id没出现在where句中 而出现在set~到where之间的句子当中 那么这个句子该如何写?? 求高人!!

解决方案 »

  1.   

    楼主和那个qiyueqinglian搞同样的事情?
    http://topic.csdn.net/u/20110610/17/fa7cf824-b181-4623-93d1-6ef6c7d4b80f.htmlsql = "update books  set id="+oldid+" bookName=..... where id="+newid;
      

  2.   

    sql = "update books set id="+oldid+", bookName=..... where id="+newid;
      

  3.   

    谢谢楼上 你理解错啦 
    我是说要是换个其他的int型的 如何在set后边添加??、
      

  4.   

    1:id是主键吗?如果是的,这个是无法更新的!
    2:不是主键一样的写呀,但是你用什么做更新条件?String sql = "update books set id = "+id+", bookName='" + bookName + "',ISBN='"
    + ISBN + "',publisher='" + publisher + "',author='" + author
    + "' where ?;
    这里你用什么做更新条件,ID不行了,因为你写在了set中间,主键ID是不能更新的,这是数据库的规定!
      

  5.   

    楼主的意思是不是: 如果 set 和 where 之间加上一个int类型的字段?
    String sql = "update books set bookName='" + bookName + "',ISBN='"
    + ISBN + "',publisher='" + publisher + "',author='" + author
    + "', number= " + number+ " where id="+id;
      

  6.   

    假设id2是int型,
    String sql = "update books set bookName='" + bookName + "',ISBN='"
    + ISBN + "',publisher='" + publisher + "',author='" + author
    + "' ,id2="+id2" where id="+id;