package dao.jdbc; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; import java.util.List; import util.DBConnection; import dao.EmployeeDAO; import entity.Employee; public class EmployeeDAOJdbcImpl implements EmployeeDAO { public List<Employee> findALL() throws Exception { ArrayList<Employee> list = new ArrayList<Employee>(); Connection conn = DBConnection.getConnection(); PreparedStatement ps = conn.prepareStatement("select * from t_emp"); ResultSet rs = ps.executeQuery(); while(rs.next()) { Employee e = new Employee(); e.setId(rs.getInt("id")); e.setName(rs.getString("name")); e.setAge(rs.getInt("age")); e.setSalary(rs.getDouble("salary")); list.add(e); } DBConnection.close(rs, ps, conn); return list; } public void insertEmp(Employee e) throws Exception { Connection conn = DBConnection.getConnection(); PreparedStatement ps = conn.prepareStatement("insert into t_emp(name,age,salary) values(?,?,?)"); ps.setString(1, e.getName()); ps.setInt(2,e.getAge()); ps.setDouble(3, e.getSalary()); ps.executeUpdate(); System.out.println("插入成功"); DBConnection.close(ps, conn); } public void deleteEmpById(int id) throws Exception { Connection conn = DBConnection.getConnection(); PreparedStatement ps = conn.prepareStatement("delete from t_emp where id=?"); ps.setInt(1,id); ps.executeUpdate(); DBConnection.close(ps, conn); } public void updateEmp(Employee e) throws Exception { Connection conn = DBConnection.getConnection(); PreparedStatement ps = conn.prepareStatement("update t_emp set name=?,age=?,salary=? where id=?"); ps.setString(1, e.getName()); ps.setInt(2,e.getAge()); ps.setDouble(3, e.getSalary()); ps.setInt(4, e.getId()); ps.executeUpdate(); DBConnection.close(ps, conn); } public Employee findEmpById(int id) throws Exception { Employee e = null; Connection conn = DBConnection.getConnection(); PreparedStatement ps = conn.prepareStatement("select * from t_emp where id=?"); ps.setInt(1, id); ResultSet rs = ps.executeQuery(); while(rs.next()) { e = new Employee(); e.setId(rs.getInt("id")); e.setName(rs.getString("name")); e.setAge(rs.getInt("age")); e.setSalary(rs.getDouble("salary")); } DBConnection.close(rs, ps, conn); return e; } }

996171721 LV7
9月24日
2131234536546 LV3
9月8日
王王王229 LV1
9月3日
lljp285248450 LV2
8月7日
kaysar0704 LV1
8月1日
sixttowsix LV1
7月5日
asadda LV2
6月27日
jsp老师sb LV1
6月19日
微信网友_6522950137778176 LV1
6月17日
hongdongdong LV11
6月16日

tcxxm1
9月27日
暂无贡献等级
fesfefe LV4
9月26日
2036495585 LV8
9月25日
zhaozhiwen123
9月18日
暂无贡献等级
zj20020510 LV5
9月14日
2131234536546 LV3
9月8日
vilychan LV2
9月4日
王王王229 LV1
9月3日
微信网友_6631309708414976 LV3
9月2日
sunlghy LV3
8月31日