⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userinfodaobean.java~16~

📁 一个由B/S做的宠物医院
💻 JAVA~16~
字号:
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;
    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 + -