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

📄 classofemployee.java~10~

📁 基于mvc的宠物管理系统。servlet+jsp
💻 JAVA~10~
字号:
//该类实现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) { //该方法用于验证用户登陆信息
       return true;
    }

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

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

    public ArrayList employeeQueryAll(int perPage, int pageNumber) { //该方法用于分页查询所有员工的信息
        ArrayList objArrayList = new ArrayList();
        String sqlCommand = "{call proc_employee (?,?)}";
        try {
            CallableStatement cs = objDBOperate.getConnect("petclinic").prepareCall(sqlCommand);
            cs.setInt(1, perPage);
            cs.setInt(2, pageNumber);
            ResultSet rs = cs.executeQuery();
            while (rs.next()) {
                Employee objEmployee = new Employee();
                objEmployee.setId(rs.getInt(1));
                objEmployee.setName(rs.getString(2));
                objEmployee.setPassword(rs.getString(3));
                objArrayList.add(objEmployee);
            }
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
        return objArrayList;

    }

    public void employeeUpdate(Employee objEmployee) { //该方法用于修改指定员工的密码
        String sqlCommand="update employee set name=?,password=? where id=?";
        try {
          PreparedStatement ps=  objDBOperate.getPreparedStatement("petclinic",sqlCommand);
          ps.setString(1,objEmployee.getName());
          ps.setString(2,objEmployee.getPassword());
          ps.setInt(3,objEmployee.getId());
          ps.execute();
        } catch (Exception ex) {
           System.out.println(ex.getMessage());
        }
    }

    public int totalPages() {
        int totalPages = 0;
        String sqlCommand = "select count(*) from employee";

        try {
            PreparedStatement objStatement = objDBOperate.getPreparedStatement("petclinic",sqlCommand);
            ResultSet rs = objStatement.executeQuery();
            while(rs.next())
            {
            totalPages = rs.getInt(1);
            }

        } catch (Exception ex) {
            System.out.println("错误提示:" + ex.getMessage());
        }
        if(totalPages%15==0)
            return totalPages/15;
        else
            return (totalPages/15)+1;
    }
}

⌨️ 快捷键说明

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