和插入语句相似,表单传值,在另一个页面接收数据并连接数据库进行更新;
语句如下:
<% request.setCharacterEncoding("UTF-8");
String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=Users";
Connection conn=null;
String userName="sa";
String pwd="xxxx";
//Class.forName(driverName);
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(dbURL,userName,pwd); String sql="update Users2 set password=?,question=?,answer=?,gender=? where username=?;";
PreparedStatement stmp=conn.prepareStatement(sql); String username=request.getParameter("User");
String password=request.getParameter("pwd");
String question=request.getParameter("secret");
String answer=request.getParameter("pwd2");
String gender=request.getParameter("sexy"); stmp.setString(,username);
stmp.setString(,password);
stmp.setString(,question);
stmp.setString(,answer);
stmp.setString(,gender); int n=stmp.executeUpdate();
if(n==){%>数据修改成功!<br><%}
else{%>数据修改失败!<br><%}
if(stmp!=null){
stmp.close();
}
if(conn!=null){
conn.close();
}
%>