三国之帝王召唤系统:SQL在JSP中占位符的使用方法!~

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/08 05:34:40
public void changePassword(String password) {
DBConnect dbc = null;
try{
dbc = new DBConnect();
dbc.prepareStatement("UPDATE user SET UserPassword = ? WHERE UserName = ?");
dbc.setBytes(1,password.getBytes("GB2312"));
dbc.setBytes(2,userName.getBytes("GB2312"));
dbc.executeUpdate();
}catch(Exception e){
System.err.println(e);
}finally{
try{
dbc.close();
}catch(Exception e){
e.printStackTrace();
}
}

}
占位符
就象这个是怎么用呢?是要怎么用的,条件的,怎么用拉2
具体点,谢谢QQ185259693

?是个占位符这个地方是可以被替换的。
dbc.setBytes(1,password.getBytes("GB2312")); 替换第一个问号
dbc.setBytes(2,userName.getBytes("GB2312")); 替换第二个问号
sql语句也可以这样写,如下:
String strSQL ="UPDATE user SET UserPassword = '" + password + "'" + " WHERE UserName = '" + "userName" + "'";