员工管理系统作业数据准备执行下面的sql语句完成员工表的创建以及测试数据的添加Navicat Premium Data TransferSource Server myconnSource Server Type MySQLSource Server Version 80031Source Host localhost3306Source Schema xjaTarget Server
- 查询部门员工
public List
- 办理员工入职
public boolean addEmployee(Employee employee) { Connection conn = null; PreparedStatement ps = null; String sql = "INSERT INTO employee (eno, ename, salary, dname, hiredate) VALUES (?, ?, ?, ?, ?)"; try { conn = DBUtil.getConnection(); ps = conn.prepareStatement(sql); ps.setInt(1, employee.getEno()); ps.setString(2, employee.getEname()); ps.setFloat(3, employee.getSalary()); ps.setString(4, employee.getDname()); ps.setString(5, employee.getHiredate()); int result = ps.executeUpdate(); if (result > 0) { return true; } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(conn, ps); } return false; }
- 调整员工薪资
public boolean updateEmployeeSalary(int eno, float salary) { Connection conn = null; PreparedStatement ps = null; String sql = "UPDATE employee SET salary = ? WHERE eno = ?"; try { conn = DBUtil.getConnection(); ps = conn.prepareStatement(sql); ps.setFloat(1, salary); ps.setInt(2, eno); int result = ps.executeUpdate(); if (result > 0) { return true; } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(conn, ps); } return false; }
- 员工离职
public boolean deleteEmployee(int eno) { Connection conn = null; PreparedStatement ps = null; String sql = "DELETE FROM employee WHERE eno = ?"; try { conn = DBUtil.getConnection(); ps = conn.prepareStatement(sql); ps.setInt(1, eno); int result = ps.executeUpdate(); if (result > 0) { return true; } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(conn, ps); } return false; }
- 分页查询员工
public List
原文地址: https://www.cveoy.top/t/topic/gJca 著作权归作者所有。请勿转载和采集!