首页>代码>JSP+Struts2开发诚欣企业免费电子商城网站系统源代码下载>/企业电子商城/Shopping/src/com/wy/dao/AfficheDao.java
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;

  }

}
最近下载更多
sunshine255  LV5 2022年4月30日
lzlzyw  LV14 2022年3月24日
1487878315  LV10 2021年11月29日
夏未尽花已落  LV1 2020年6月14日
12385522272  LV4 2020年4月28日
hancro  LV5 2020年3月11日
sunskyasd  LV6 2019年12月18日
528679484  LV5 2019年10月23日
caifangfang  LV5 2019年6月25日
itscod  LV6 2019年6月16日
最近浏览更多
1134116035 2月28日
暂无贡献等级
ljhgff  LV1 2月18日
heshao  LV2 2月7日
打工皇帝  LV1 2023年11月3日
qhlssd 2023年7月31日
暂无贡献等级
smmmm123  LV8 2022年12月28日
maxking  LV2 2022年7月13日
明天下午去  LV2 2022年6月15日
haoshuai547  LV1 2022年5月29日
wangyunhao  LV10 2022年5月28日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友