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

📄 classofemployee.java~6~

📁 基于mvc的宠物管理系统。servlet+jsp
💻 JAVA~6~
字号:
//该类实现InterfaceOfEmployee接口,用于实现员工各种操作的方法

package com.richard.dao;

import java.util.*;
import com.richard.dto.*;
import java.sql.*;

public class ClassOfEmployee implements InterfaceOfEmployee {

    DBOperate objDBOperate = new DBOperate();

    public ClassOfEmployee() {
    }

    public boolean check(Employee objEmployee) { //该方法用于验证用户登陆信息
        boolean flag = false;
        String employeeName = objEmployee.getName();
        String employeePassword = objEmployee.getPwssword();
        String sqlCommand = "select * from employee where name='" +
                            employeeName + "' and password='" +
                            employeePassword + "'";
        try {
            ResultSet rs = objDBOperate.getResultSet("petclinic", sqlCommand);
            if (rs.next()) {
                flag = true;
            }
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
        return flag;
    }

    public void employeeDelete(Employee objEmployee) { //该方法用于根据员工姓名删除一条员工记录
        String employeeName = objEmployee.getName();
        String sqlCommand = "delete employee where name='" + employeeName + "'";
        PreparedStatement objStatement = objDBOperate.getPreparedStatement(
                "petclinic", sqlCommand);
        try {
            objStatement.execute();
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
    }

    public void employeeInsert(Employee objEmployee) { //该方法用于插入一条新的员工记录
        String employeeName = objEmployee.getName();
        String employeePassword = objEmployee.getPwssword();
        String sqlCommand = "insert into employee (name,password) values ('" +
                            employeeName + "','" + employeePassword + "')";
        PreparedStatement objStatement = objDBOperate.getPreparedStatement(
                "petclinic", sqlCommand);
        try {
            objStatement.execute();
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }

    }

    public ArrayList employeeQuery(Employee objEmployee) { //该方法用于根据员工姓名查询相关的员工记录,用于模糊查询
        String employeeName = objEmployee.getName();
        ArrayList objArrayList = new ArrayList();
        String sqlCommand = "select * from employee where name like '%" +
                            employeeName + "%'";
        try {
            ResultSet rs = objDBOperate.getResultSet("petclinic", sqlCommand);
            while (rs.next()) {
                Employee rsEmployee = new Employee();
                rsEmployee.setName(rs.getString(1)); //从数据库中取出满足条件的用户名放入Employee对象中
                rsEmployee.setPwssword(rs.getString(2));
                objArrayList.add(rsEmployee); //Employee对象添加至集合
            }
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
        return objArrayList;
    }

    public ArrayList employeeQueryAll() { //该方法用于查询所有员工的记录
        ArrayList objArrayList = new ArrayList();
        String sqlCommand = "select * from employee";
        try {
            ResultSet rs = objDBOperate.getResultSet("petclinic", sqlCommand);
            while (rs.next()) {
                Employee rsEmployee = new Employee();
                rsEmployee.setName(rs.getString(1)); //从数据库中取出满足条件的用户名放入Employee对象中
                rsEmployee.setPwssword(rs.getString(2));
                objArrayList.add(rsEmployee); //Employee对象添加至集合
            }
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
        return objArrayList;

    }

    public void employeeUpdate(Employee objEmployee) { //该方法用于修改指定员工的密码
        String employeeName = objEmployee.getName();
        String employeePassword = objEmployee.getPwssword();
        String sqlCommand = "update employee set password='" + employeePassword +
                            "' where name='" + employeeName + "'";
        PreparedStatement objStatement = objDBOperate.getPreparedStatement(
                        "petclinic", sqlCommand);
                try {
                    objStatement.execute();
                } catch (Exception ex) {
                    System.out.println(ex.getMessage());
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -