?? userinfodaobean.java
字號:
package pethospitalsystem;
import java.sql.*;
import java.util.*;
//相對應用戶信息表的操作Bean.
public class UserInfoDaoBean {
public UserInfoDaoBean() {
}
SQLBean sqlb = new SQLBean();
UserInfoBean uib = new UserInfoBean();
Connection con;
Statement stmt;
ResultSet rs;
String PwdQuestion = "";
//得到數據庫連接對象.
public Connection getCon() {
if (sqlb.getCon() != null) {
con = sqlb.getCon();
}
return con;
}
//判斷注冊的用戶名是否存在.
public boolean validateusername() {
try {
this.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;
}
} catch (Exception ex) {
System.out.println(ex.getMessage());
return false;
}
}
//插入注冊用戶信息到UserInfo表中.
public boolean insertdata() {
try {
this.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;
} catch (Exception ex) {
System.out.println(ex.getMessage());
return false;
}
}
//用戶登陸時的驗證.
public boolean Login() {
try {
this.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;
}
} catch (Exception ex) {
System.out.println(ex.getMessage());
return false;
}
}
//用戶取回密碼第一步,通過用戶名和出生日期判斷該用戶是否存在或出生日期是否輸入正確,返回密碼提示問題.
public String getPasswordOne() {
try {
this.getCon();
String strSql = "select * from UserInfo where UserName='" +
uib.getUserName() + "' and UBirthday='" +
uib.getUBirthday()+"'";
stmt = con.createStatement();
rs = stmt.executeQuery(strSql);
if (rs.next()) {
PwdQuestion = rs.getString(3);
}
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
return PwdQuestion;
}
//用戶取回密碼第二步,通過回答設置的密碼提示問題來重新設置密碼.
public boolean getPasswordTwo() {
try {
this.getCon();
String strSql = "select * from UserInfo where UserName='" +
uib.getUserName() + "' and UPwdAnswer='" +
uib.getUPwdAnswer()+"'";
String strUpdate = "Update UserInfo set UPassword='" +
uib.getUPassword() + "' where UserName='" +
uib.getUserName() + "'";
stmt = con.createStatement();
rs = stmt.executeQuery(strSql);
if (rs.next()) {
stmt.executeUpdate(strUpdate);
return true;
} else {
return false;
}
} catch (Exception ex) {
System.out.println(ex.getMessage());
return false;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -