PreparedStatement修改数据库数据  用update 修改一些 在jtable中选中的数据行  “update 表名 set 表名_price=? where 表名_price=x" 其中这个x 是个变量  怎么来实现了?????搞不懂

解决方案 »

  1.   

    PreparedStatement ps = con.prepareStatement(“update 表名 set 表名_price=? where 表名_price=x");
    ps.setInt(1,你的price)
    ResultSet rs = ps.executeUpdate();
      

  2.   

    那就改成变量就行了
    PreparedStatement ps = con.prepareStatement(“update 表名 set 表名_price=? where 表名_price=x"); 
    ps.setInt(1,你的第一个问号想代表值) 
      

  3.   

    LZ的意思是在引号中插入变量吗?我知道C#中是怎么写的,不知道Java中是不是这样:
    PreparedStatement ps = con.prepareStatement("update 表名 set 表名_price=? where 表名_price='"+x+"'"); 
      

  4.   


    String sqlupdate="update 表名 set 表名.price=? where 表名.price=?";
    PreparedStatement pstmt=null;
    try {
    pstmt=dbBean.getPreparedStatement(sqlupdate);
    pstmt.setString(1,price);
    pstmt.setString(2,price);
    pstmt.executeUpdate();

    } catch (SQLException e) {
    e.printStackTrace();
    }finally{
    try {
    if(pstmt!=null)
    pstmt.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
      

  5.   

    多谢各位了  问题解决了 嘿嘿    解决办法和 flush_520的差不多    非常感谢各位