package com.wy.dao; import java.sql.*; import java.util.*; import com.wy.tool.JDBConnection; import com.wy.domain.AfficheForm; //对公告信息的操作 public class AfficheDao { private Connection connection = null; //定义连接的对象 private PreparedStatement ps = null; //定义预准备的对象 private JDBConnection jdbc = null; //定义数据库连接对象 public AfficheDao() { jdbc = new JDBConnection(); connection = jdbc.connection; //利用构造方法取得数据库连接 } //删除的方法 public void deleteAffiche(Integer id) { try { ps = connection.prepareStatement("delete from tb_affiche where id=?"); ps.setInt(1, id.intValue()); ps.executeUpdate(); ps.close(); } catch (SQLException ex) { ex.printStackTrace(); } } //修改的方法 public void updateAffiche(AfficheForm form) { try { ps = connection.prepareStatement("update tb_affiche set name=?,content=? where id=?"); ps.setString(1, form.getName()); ps.setString(2, form.getContent()); ps.setInt(3, form.getId().intValue()); ps.executeUpdate(); ps.close(); } catch (SQLException ex) { ex.printStackTrace(); } } //添加的方法 public void insertAffiche(AfficheForm form) { try { ps = connection.prepareStatement("insert into tb_affiche values (null,?,?,now())"); ps.setString(1, form.getName()); ps.setString(2, form.getContent()); ps.executeUpdate(); ps.close(); } catch (SQLException ex) { ex.printStackTrace(); } } //以数据库流水号为条件查询信息 public AfficheForm selectOneAffiche(Integer id) { AfficheForm affiche = null; try { ps = connection.prepareStatement("select * from tb_affiche where id=?"); ps.setInt(1, id.intValue()); ResultSet rs = ps.executeQuery(); while (rs.next()) { affiche = new AfficheForm(); affiche.setId(Integer.valueOf(rs.getString(1))); affiche.setName(rs.getString(2)); affiche.setContent(rs.getString(3)); affiche.setIssueTime(rs.getString(4)); } } catch (SQLException ex) { ex.printStackTrace(); } return affiche; } //全部查询的方法 public List selectAffiche() { List list = new ArrayList(); AfficheForm affiche = null; try { ps = connection.prepareStatement("select * from tb_affiche order by id DESC"); ResultSet rs = ps.executeQuery(); while (rs.next()) { affiche = new AfficheForm(); affiche.setId(Integer.valueOf(rs.getString(1))); affiche.setName(rs.getString(2)); affiche.setContent(rs.getString(3)); affiche.setIssueTime(rs.getString(4)); list.add(affiche); } } catch (SQLException ex) { ex.printStackTrace(); } return list; } }
最近下载更多
LYLHYC LV5
2023年8月2日
一勺枣糕 LV3
2023年7月5日
微信网友_6518834447732736 LV1
2023年6月14日
846488283 LV4
2023年5月31日
西域行者 LV3
2023年4月24日
qiuaizhang LV3
2023年4月10日
1762806977 LV4
2023年3月15日
阿达asdw1 LV4
2023年3月13日
微信网友_6008098523172864 LV3
2023年3月8日
263648 LV7
2023年2月13日
最近浏览更多
阿时23428 LV15
3月18日
yanixh LV1
2月19日
asddwh LV12
2023年12月29日
hanzhuohong LV1
2023年12月25日
人哇我
2023年12月25日
暂无贡献等级
微信网友_6786215447367680 LV4
2023年12月20日
lee123321 LV22
2023年12月19日
2385649653 LV7
2023年12月13日
komorebi123987 LV5
2023年12月8日
微信网友_6768249801986048 LV1
2023年12月8日