sql = "update userinfo set username=?,password=?,ip=? where username=" + username;pstmt = conn.prepareStatement(sql);
pstmt.setString(1, username);
pstmt.setString(2, password);
pstmt.setString(3, IP);update语句中 能用?代替吗。???????我知道insert 语句中能用。
sql = "insert into userinfo (username,password,ip) values(?,?,?)";

解决方案 »

  1.   

    update和insert一样
      

  2.   

    反正我试了一下,像我那样写的update是不能用的,不知道是不是还有其他我不知道的方法。
      

  3.   

    可以的,这是我以前写的,你是不是没写i = pstmt.executeUpdate();
    /*
     * 通过id修改用户
     */
    public boolean user_update(int id, String usp) {
    // TODO Auto-generated method stub
    int i=0;
    String sql="update tb_user set user_password = ? where id = ?";
    //System.out.println(sql);
    conn=JDBCUtil.getConnection();
    try {
    pstmt=conn.prepareStatement(sql);
    pstmt.setString(1, usp);
    pstmt.setInt(2, id);
    i = pstmt.executeUpdate();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }finally{
    JDBCUtil.close(conn, stmt, pstmt, rs);
    }
    return i>0;
    }
    }