首页>代码>java web慧心人力资源管理系统>/src/com/yuki/dao/Staff_Jdbc.java
001package com.yuki.dao;
002 
003import java.sql.*;
004import java.util.ArrayList;
005import java.util.List;
006 
007import com.yuki.servlet.index;
008import com.yuki.staff.*;
009 
010public class Staff_Jdbc {
011    private Connection conn = null;
012    public PreparedStatement pst = null;
013    public ResultSet rst = null;
014    private String sql=null;
015    private boolean ret=false;
016 
017    //增删改
018    public boolean zeng(Staff staff){
019        sql="insert into tb_staff_info values(null,?,?,?,?)";
020        ret = Transform(sql, staff.getName(), staff.getGender(), staff.getBirthday(), staff.getPhone());
021        return ret;
022    }
023    public boolean shan(Staff staff){
024        sql="delete from tb_staff_info where staff_id=?";
025       ret = Transform(sql, staff.getId());
026        return ret;
027    }
028    public boolean gai(Staff staff){
029        sql="update tb_staff_info set staff_name=?,staff_sex=?,staff_birthday=?,staff_phone=? where staff_id=?)";
030        ret = Transform(sql, staff.getName(), staff.getGender(), staff.getBirthday(), staff.getPhone(),staff.getId());
031        return ret;
032    }
033    //变
034    private boolean Transform(String sql, Object... objects) {
035        try {
036            conn = DbConnection.getConn();
037            pst = conn.prepareStatement(sql);
038            for (int i = 0; i < objects.length; i++) {
039                pst.setObject(i + 1, objects[i]);
040            }
041            int rows = pst.executeUpdate();
042            DbConnection.getClose(conn, pst, rst);
043            return rows > 0;
044        } catch (SQLException e) {
045            e.printStackTrace();
046        }
047        return false;
048    }
049 
050    //查
051    public List<Staff> select() {
052        List<Staff> StaList=new ArrayList<>();
053        conn = DbConnection.getConn();
054        try {
055            sql="select * from tb_staff_info;";
056            pst = conn.prepareStatement(sql);
057            rst = pst.executeQuery();
058            while(rst.next()) {
059                Staff staff=new Staff();
060                staff.setId(rst.getInt("staff_id"));
061                staff.setName(rst.getString("staff_name"));
062                staff.setGender(rst.getString("staff_sex"));
063                staff.setBirthday(rst.getString("staff_birthday"));
064                staff.setPhone(rst.getString("staff_phone"));
065                StaList.add(staff);
066            }
067            DbConnection.getClose(conn, pst, rst);
068        } catch (SQLException e) {
069            e.printStackTrace();
070        }
071        return StaList;
072    }
073    public Staff find(int id) {
074        conn = DbConnection.getConn();
075        Staff staff=new Staff();
076        try {
077            sql="select * from tb_staff_info where staff_id="+id;
078            pst = conn.prepareStatement(sql);
079            rst = pst.executeQuery();
080            while(rst.next()) {
081                staff.setId(id);
082                staff.setName(rst.getString("staff_name"));
083                staff.setGender(rst.getString("staff_sex"));
084                staff.setBirthday(rst.getString("staff_birthday"));
085                staff.setPhone(rst.getString("staff_phone"));
086            }
087            DbConnection.getClose(conn, pst, rst);
088        } catch (SQLException e) {
089            e.printStackTrace();
090        }
091        return staff;
092    }
093     
094     
095     
096//    public static void main(String[] args) {
097//       Staff sta=new Staff_Jdbc().find(1);
098//      System.out.println(sta);
099//       
100//    }
101     
102}
最近下载更多
long123_356  LV8 2024年12月22日
cong58cong  LV8 2024年6月26日
今晚都别睡啦  LV9 2024年6月1日
微信网友_6906962132258816  LV7 2024年3月22日
RAINK_L  LV3 2023年12月13日
jiemomo  LV12 2023年10月19日
微信网友_6672184532766720  LV3 2023年10月10日
诺一啊啊啊啊啊  LV3 2023年6月15日
KAIzx11  LV7 2023年6月13日
gala209  LV3 2023年2月2日
最近浏览更多
444105047  LV6 1月17日
cxdddd  LV1 2024年12月31日
yongle  LV1 2024年12月31日
long123_356  LV8 2024年12月22日
120_wu  LV4 2024年12月2日
yimaoermao  LV1 2024年11月28日
张泽帅  LV6 2024年10月18日
040313  LV1 2024年10月16日
4324234ty 2024年7月2日
暂无贡献等级
cong58cong  LV8 2024年6月26日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友