String upd = "update book set ....where book_id=?";
ps.setString(1,book_id);

解决方案 »

  1.   

    就是,一般为了处理好数据库中的问题,使用PreparedStatement来代替Statement的操作可以是很多有利之处!
    你想根据自己得到的条件去组织sql语句,在使用PreparedStatement中可以先写一个完整的sql语句其中输入参数用”?“来替代,在下面来根据它的位置设定它的值就是了!
      

  2.   

    加双引号编译不通过,下面这样也不行,能帮我具体改一下么?String upd = "update Book set bookname='?', Author='?', Press_ID='?', Price='?', Our_Price='?',category_ID='?', Book_Ename='?', Translator='?', Description='?' where Book_ID= bookid;";
        PreparedStatement ps=con.prepareStatement(upd);
        ps.setString(1,bookname);
    ps.setString(2,author);
    ps.setInt(3,Pressid);
    ps.setFloat(4,price);
    ps.setDouble(5,ourprice);
    ps.setInt(6,categoryid);
    ps.setString(7,bookename);
    ps.setString(8,translator);
    ps.setString(9,description);
    ps.executeUpdate();
      

  3.   

    String upd = "update Book set bookname=?, Author=?, Press_ID=?, Price=?, Our_Price=?,category_ID=?, Book_Ename=?, Translator=?, Description=? where Book_ID= bookid";
        PreparedStatement ps=con.prepareStatement(upd);
        ps.setString(1,bookname);
    ps.setString(2,author);
    ps.setInt(3,Pressid);
    ps.setFloat(4,price);
    ps.setDouble(5,ourprice);
    ps.setInt(6,categoryid);
    ps.setString(7,bookename);
    ps.setString(8,translator);
    ps.setString(9,description);
    ps.executeUpdate();
    你的错误:1.? 外面是不需要引号的2:upd字符串后面的;是不需要的
    另外:Book_ID= bookid也可改成Book_ID= ?,ps.setInt(10,Book_ID)