📄 userinfodaobean.java~14~
字号:
package pethospitalsystem;
import java.sql.*;
//相对应用户信息表的操作Bean.
public class UserInfoDaoBean {
public UserInfoDaoBean() {
}
SQLBean sqlb=new SQLBean();
UserInfoBean uib=new UserInfoBean();
Connection con;
Statement stmt;
ResultSet rs;
//判断注册的用户名是否存在.
public boolean validateusername(){
try {
if(sqlb.getCon()!=null){
con=sqlb.getCon();
String strSql="select * from UserInfo where UserName='"+uib.getUserName()+"'";
stmt=con.createStatement();
rs=stmt.executeQuery(strSql);
if(rs.next()){
return true;
}else{
return false;
}
}else{
return false;
}
} catch (Exception ex) {
System.out.println(ex.getMessage());
return false;
}
}
//插入注册用户信息到UserInfo表中.
public boolean insertdata(){
try {
if(sqlb.getCon()!=null){
con=sqlb.getCon();
String strSql="Insert into UserInfo values('"+uib.getUserName()+"','"+uib.getUPassword()+
"','"+uib.getUPwdQuestion()+"','"+uib.getUPwdAnswer()+"','"+uib.getUTrueName()+
"','"+uib.getUGender()+"','"+uib.getUBirthday()+"','"+uib.getUIdType()+
"','"+uib.getUIdCard()+"','"+uib.getUEmail()+"')";
stmt=con.createStatement();
stmt.executeUpdate(strSql);
return true;
}else{
return false;
}
} catch (Exception ex) {
System.out.println(ex.getMessage());
return false;
}
}
//用户登陆时的验证.
public boolean Login(){
try {
if(sqlb.getCon()!=null){
con=sqlb.getCon();
//通过用户名查找数据.
String strSql="select * from UserInfo where UserName='"+uib.getUserName()+"'";
String pwd="";
stmt=con.createStatement();
rs=stmt.executeQuery(strSql);
if(rs.next()){
//如果该用户名存在,则将密码取出来进行下一步判断.
pwd=rs.getString(2);
if(pwd.equals(uib.getUPassword())){
//密码也正确就直接返回true.
return true;
}else{
return false;
}
}else{
return false;
}
}else{
return false;
}
} catch (Exception ex) {
System.out.println(ex.getMessage());
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -