package com.mitsui.dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import com.mitsui.domain.Agreement; import com.mitsui.util.ConnectionUtil; public class AgreementDao { public boolean addAgreement(Agreement agreement){ String sql = "insert into staffagreement(agreement_id,p_id,agreement_btime,agreement_etime,position,agreement_content) values(?,?,?,?,?,?)"; Object[] params = { agreement.getAgreement_id(), agreement.getP_id(), agreement.getAgreement_btime(), agreement.getAgreement_etime(), agreement.getPosition(), agreement.getAgreement_content(), }; return ConnectionUtil.executeUpdate(sql, params); } public List<Agreement> queryAllAgreement(){ String sql = "select * from staffagreement"; Connection conn = ConnectionUtil.getConection(); PreparedStatement ps = null; try { ps = conn.prepareStatement(sql); ResultSet rs = ps.executeQuery(); Agreement u = null; List<Agreement> agreements = new ArrayList<Agreement>(); while(rs.next()){ int agreement_id = rs.getInt("agreement_id"); int p_id = rs.getInt("p_id"); String agreement_btime = rs.getString("agreement_btime"); String agreement_etime= rs.getString("agreement_etime"); String position = rs.getString("position"); String agreement_content = rs.getString("agreement_content"); u = new Agreement(agreement_id, p_id, agreement_btime, agreement_etime, position, agreement_content); agreements.add(u); } return agreements; } catch (SQLException e) { e.printStackTrace(); return null; } } public boolean deleteAgreement(Integer agreement_id){ String sql = "delete from staffagreement where agreement_id = ?"; Object[] params = { agreement_id }; return ConnectionUtil.executeUpdate(sql, params); } public Agreement queryAgreement(Integer agreement_id){ String sql = "select * from staffagreement where agreement_id = ?"; Connection conn = ConnectionUtil.getConection(); PreparedStatement ps = null; try { ps = conn.prepareStatement(sql); ps.setInt(1, agreement_id); ResultSet rs = ps.executeQuery(); Agreement u = null; if(rs.next()){ int p_id = rs.getInt("p_id"); String agreement_btime = rs.getString("agreement_btime"); String agreement_etime = rs.getString("agreement_etime"); String position = rs.getString("position"); String agreement_content = rs.getString("agreement_content"); u = new Agreement(agreement_id, p_id, agreement_btime, agreement_etime, position, agreement_content); } return u; } catch (SQLException e) { e.printStackTrace(); return null; } } public boolean updateAgreement(Agreement agreement){ String sql = "update staffagreement set p_id = ?,agreement_btime = ?,agreement_etime = ?,position = ?,agreement_content = ?where agreement_id = ?"; Object[] params = { agreement.getP_id(), agreement.getAgreement_btime(), agreement.getAgreement_etime(), agreement.getPosition(), agreement.getAgreement_content(), agreement.getAgreement_id(), }; return ConnectionUtil.executeUpdate(sql, params); } public static List<Agreement> queryOneAgreement(int id) { String sql = "select * from staffagreement where P_id = "+ id +""; Connection conn = ConnectionUtil.getConection(); PreparedStatement ps = null; try { ps = conn.prepareStatement(sql); ResultSet rs = ps.executeQuery(); Agreement u = null; List<Agreement> agreements = new ArrayList<Agreement>(); while(rs.next()){ int agreement_id = rs.getInt("agreement_id"); int p_id = rs.getInt("p_id"); String agreement_btime = rs.getString("agreement_btime"); String agreement_etime= rs.getString("agreement_etime"); String position = rs.getString("position"); String agreement_content = rs.getString("agreement_content"); u = new Agreement(agreement_id, p_id, agreement_btime, agreement_etime, position, agreement_content); agreements.add(u); } return agreements; } catch (SQLException e) { e.printStackTrace(); return null; } } }
最近下载更多
yuanshun LV6
2023年12月14日
微醺酸梅汤 LV2
2023年9月27日
husiyu LV3
2023年9月25日
duoer12 LV5
2022年12月30日
wangxiaolaugh LV2
2022年12月27日
194897762 LV4
2022年12月26日
485415187 LV6
2022年11月20日
aduahfue LV4
2022年10月25日
13940562934 LV22
2022年7月2日
donglixue LV6
2022年6月28日
最近浏览更多
自选菜
27分钟前
暂无贡献等级
张泽帅 LV6
10月18日
krispeng LV13
8月12日
liuaaa
6月24日
暂无贡献等级
微信网友_7041475584184320
6月17日
暂无贡献等级
123456cjj LV1
6月2日
暂无贡献等级
微信网友_6906962132258816 LV7
5月15日
爱丽淇 LV5
3月13日
wjh007 LV4
3月13日