个人信息管理系统
功能模块:登录,注册,个人信息管理,通讯录管理,日程安排(选作),文件管理。
一.登陆注册
登录及注册页面有输入校验,采取struts2的校验框架实现,即-validation.xml配置文件的形式。
String sql1=“select * from user where userName=’”+personal.getUserName()+"’ "
+ “and password=’”+personal.getPassword()+"’ ";
boolean s = Select_User();
if(s){
session.put(“name”,personal.getUserName());
return SUCCESS;
}else{
return “error”;
}
String sql = “insert into user values(’”+personal.getUserName()+"’"+","+"’"+personal.getPassword() +"’"+","
+ “”+"’"+personal.getName()+"’"+","
+ “’”+personal.getSex()+"’"+","+"’"+personal.getBirth()+"’"+","+"’"+personal.getNation()+"’"+","
+""+"’"+personal.getEdu()+"’"+","+""+"’"+personal.getWork()+"’"+","
+""+"’"+personal.getPhone()+"’"+","+""+"’"+personal.getPlace()+"’"+","+""+"’"+personal.getEmail()+"’"+")";
stmt.executeUpdate(sql);
return SUCCESS;
二.对个人信息的删,改,查
主页面显示个人基本信息:登录名、用户密码、用户姓名、用户性别、出生日期、用户名族、用户学历、用户职称、用户电话、用户地址、用户邮箱。
从数据库中进行条件查询,并添加到集合中,通过session传到页面。
String sql=“select * from user where userName=’”+personal.getUserName()+"’ “;
rs = stmt.executeQuery(sql);
return rs;
while(rs.next()){
String userName = rs.getString(“userName”);
String name = rs.getString(“name”);
String sex = rs.getString(“sex”);
String birth = rs.getString(“birth”);
String nation = rs.getString(“nation”);
String edu = rs.getString(“edu”);
String work = rs.getString(“work”);
String phone = rs.getString(“phone”);
String place = rs.getString(“place”);
String email = rs.getString(“email”);
Personal person = new Personal(userName,name,sex,
birth,nation,edu,work,phone,place,email);
list.add(person);
}
String sql = “update user set userName = '”+personal.getUserName()+”’ , "
+ “name = '”+personal.getName()+"’ , "
+ “sex = '”+personal.getSex()+"’ , "
+ “birth = '”+personal.getBirth()+"’ , "
+ “nation = '”+personal.getNation()+"’ , "
+ “edu = '”+personal.getEdu()+"’ , "
+ “work = '”+personal.getWork()+"’ , "
+ “phone = '”+personal.getPhone()+"’ , "
+ “place = '”+personal.getPlace()+"’ , "
+ “email = '”+personal.getEmail()+"’ where userName = ‘"+personal.getUserName()+"’ ";
stmt.executeUpdate(sql);
return SUCCESS;
三.对通讯录的删,改,查
用户可以浏览通讯录列表,按照姓名检索 。
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
String sql = “insert into friends values(’”+friend.getFriendName()+"’"+","+"’"+friend.getPhone() +"’"+","+"’"+friend.getEmail()+"’"+","
+ “’”+friend.getWorkplace()+"’"+","+"’"+friend.getPlace()+"’"+","+"’"+friend.getQQ()+"’"+")";
stmt.executeUpdate(sql);
return SUCCESS;
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
String sql=“delete from friends where friendName=’”+friend.getFriendName()+"’";
stmt.executeUpdate(sql);
return SUCCESS;
String sql = “update friends set friendName = '”+friend.getFriendName()+"’ , "
+ “phone = '”+friend.getPhone()+"’ , "
+ “email = '”+friend.getEmail()+"’ , "
+ “workplace = '”+friend.getWorkplace()+"’ , "
+ “place = '”+friend.getPlace()+"’ , "
+ “QQ = '”+friend.getQQ()+"’ where friendName = ‘"+friend.getFriendName()+"’ ";
stmt.executeUpdate(sql);
return SUCCESS;
四.对日程的安排以及増,删,改,查
用户可以查看日程安排表,可以查看某一日程的时间、内容等 。
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
String sql = “insert into date values (’”+date.getUserName()+"’"+","+"’"+date.getDate()+"’"+","+"’"+date.getThing()+"’"+")";
stmt.executeUpdate(sql);
return SUCCESS;
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
String sql = “update date set userName = '”+date.getUserName()+"’ , "
+ “date = '”+date.getDate()+"’ , "
+ “thing = '”+date.getThing()+"’ where userName = ‘"+date.getUserName()+"’ and date = ‘"+date.getDate()+"’";
stmt.executeUpdate(sql);
session.put(“name”, date.getUserName());
return SUCCESS;
五.文件的上传
查找文件信息,并把文件的信息保存到session对象中
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
String sql =
"insert into file values('"+getTitle()+"' , '"+getUploadFileFileName() +"','"+getUploadFileContentType()+"','"+uploadFile.length()/1024+"K"+"')";
stmt.executeUpdate(sql);
}
else {
return INPUT;
}
return SUCCESS;
}
总结:这次试验遇到了错误Table ‘mysql.user’ doesn’t exist。之前运行连接过数据库,后来修改了表名就一直出错,检查后代码并没有出错。
解决方法:Manage Deployments选中项目后Browse找到.metadata.me_tcat85\webapps目录下的项目,删除。重启tomcat后没有错误。