我的数据库用的是mysql,名字是db_01,账号和密码都是root
1.Change_info.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" import="java.sql.*"
pageEncoding="UTF-8"%>
用户注册信息修改
<%
String driver = "com.mysql.jdbc.Driver";
Class.forName(driver);
//2.得到链接
// URL指向要访问的数据库名world
String url = "jdbc:mysql://localhost:3306/db_01";
Connection conn=DriverManager.getConnection(url,"root","root");
//3.得到statement
Statement statement = conn.createStatement();
//4查询数据库
String name2=(String)session.getValue("name");
String sql="select * from user where usr='"+name2+"'";
ResultSet rs = statement.executeQuery(sql);
String password0="";
String confirmpwd0="";
String sex0="";
String birthday0="";
String graduateschool0="";
String qualification0="";
String address0="";
String telephone0="";
String email0="";
String question0="";
String answer0="";
String hobbies0="";
if(rs.next())
{
password0=rs.getString("passwd");
confirmpwd0=rs.getString("confirmpwd");
sex0=rs.getString("sex");
birthday0=rs.getString("birthday");
graduateschool0=rs.getString("graduateschool");
qualification0=rs.getString("qualification");
address0=rs.getString("address");
telephone0=rs.getString("telephone");
email0=rs.getString("email");
question0=rs.getString("question");
answer0=rs.getString("answer");
hobbies0=rs.getString("hobbies");
rs.close();
}
%>
修改会员信息
以下加星号(*)的是必填项
<%@include file="footer.jsp" %>
2.Check_Change_info.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" import="java.sql.*"
pageEncoding="UTF-8"%>
处理会员修改注册信息
<%@include file="title.jsp"%>
用户注册信息修改
<%
//4查询数据库
//获取提交的用户名
String strUserName=request.getParameter("txtUserName");
strUserName=new String(strUserName.getBytes("ISO8859-1"),"UTF-8");
//获取提交的密码
String strPassword=request.getParameter("txtPassword");
strPassword=new String(strPassword.getBytes("ISO8859-1"),"UTF-8");
//获取确认密码
String strConfirmpwd=request.getParameter("txtConfirmpwd");
strConfirmpwd=new String(strConfirmpwd.getBytes("ISO8859-1"),"UTF-8");
//获取注册人性别
String strSex=request.getParameter("txtSex");
strSex=new String(strSex.getBytes("ISO8859-1"),"UTF-8");
//获取出生日期
String strBirthday=request.getParameter("txtBirthday");
strBirthday=new String(strBirthday.getBytes("ISO8859-1"),"UTF-8");
//获取毕业院校
String strGraduateschool=request.getParameter("txtGraduateschool");
strGraduateschool=new String(strGraduateschool.getBytes("ISO8859-1"),"UTF-8");
//获取学历
String strQualification=request.getParameter("txtQualification");
strQualification=new String(strQualification.getBytes("ISO8859-1"),"UTF-8");
//获取地址
String strAddress=request.getParameter("province")+request.getParameter("city");
strAddress=new String(strAddress.getBytes("ISO8859-1"),"UTF-8");
//获取联系电话
String strTelephone=request.getParameter("txtTelephone");
strTelephone=new String(strTelephone.getBytes("ISO8859-1"),"UTF-8");
//获取电子信箱地址
String strEmail=request.getParameter("txtEmail");
strEmail=new String(strEmail.getBytes("ISO8859-1"),"UTF-8");
//获取找回密码提示信息
String strQuestion=request.getParameter("txtQuestion");
strQuestion=new String(strQuestion.getBytes("ISO8859-1"),"UTF-8");
//获取找回密码提示信息答案
String strAnswer=request.getParameter("txtAnswer");
strAnswer=new String(strAnswer.getBytes("ISO8859-1"),"UTF-8");
//获取个人爱好信息
String strHobbies=request.getParameter("txtHobbies");
strHobbies=new String(strHobbies.getBytes("ISO8859-1"),"UTF-8");
String driver = "com.mysql.jdbc.Driver";
Class.forName(driver);
//2.得到链接
// URL指向要访问的数据库名world
String url = "jdbc:mysql://localhost:3306/db_01";
Connection conn=DriverManager.getConnection(url,"root","root");
//3.得到statement
Statement statement = conn.createStatement();
String sql="update user set passwd='"+strPassword+"',confirmpwd='"+strConfirmpwd+"',sex='"+strSex+"',birthday='"+strBirthday+"',graduateschool='"+strGraduateschool+"',qualification='"+strQualification+"',address='"+strAddress+"',telephone='"+strTelephone+"',email='"+strEmail+"',question='"+strQuestion+"',answer='"+strAnswer+"',hobbies='"+strHobbies+"' where usr='"+strUserName+"'";
statement.executeUpdate(sql);
out.println(strUserName+ "的信息修改完毕");
%>
点击查看用户
<%@include file="footer.jsp" %>
查看后续代码请看这里后续代码