AfficheDao.java
上传用户:toby828
上传日期:2015-06-26
资源大小:8558k
文件大小:3k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. package com.dao;
  2. import java.sql.*;
  3. import java.util.*;
  4. import com.tool.JDBConnection;
  5. import com.tool.FinalConstants;
  6. import com.domain.AfficheForm;
  7. //对公告信息的操作
  8. public class AfficheDao {
  9.   private Connection connection = null; //定义连接的对象
  10.   private PreparedStatement ps = null; //定义预准备的对象
  11.   private JDBConnection jdbc = null; //定义数据库连接对象
  12.   public AfficheDao() {
  13.     jdbc = new JDBConnection();
  14.     connection = jdbc.connection; //利用构造方法取得数据库连接
  15.   }
  16.   //删除的方法
  17.   public void deleteAffiche(Integer id) {
  18.     try {
  19.       ps = connection.prepareStatement(FinalConstants.affice_delete);
  20.       ps.setInt(1, id.intValue());
  21.       ps.executeUpdate();
  22.       ps.close();
  23.     }
  24.     catch (SQLException ex) {
  25.     }
  26.   }
  27.   //修改的方法
  28.   public void updateAffiche(AfficheForm form) {
  29.     try {
  30.       ps = connection.prepareStatement(FinalConstants.affice_update);
  31.       ps.setString(1, form.getName());
  32.       ps.setString(2, form.getContent());
  33.       ps.setInt(3, form.getId().intValue());
  34.       ps.executeUpdate();
  35.       ps.close();
  36.     }
  37.     catch (SQLException ex) {
  38.     }
  39.   }
  40. //添加的方法
  41.   public void insertAffiche(AfficheForm form) {
  42.     try {
  43.       ps = connection.prepareStatement(FinalConstants.affice_insert);
  44.       ps.setString(1, form.getName());
  45.       ps.setString(2, form.getContent());
  46.       ps.executeUpdate();
  47.       ps.close();
  48.     }
  49.     catch (SQLException ex) {
  50.     }
  51.   }
  52. //以数据库流水号为条件查询信息
  53.   public AfficheForm selectOneAffiche(Integer id) {
  54.     AfficheForm affiche = null;
  55.     try {
  56.       ps = connection.prepareStatement(FinalConstants.affice_selectOne);
  57.       ps.setInt(1, id.intValue());
  58.       ResultSet rs = ps.executeQuery();
  59.       while (rs.next()) {
  60.         affiche = new AfficheForm();
  61.         affiche.setId(Integer.valueOf(rs.getString(1)));
  62.         affiche.setName(rs.getString(2));
  63.         affiche.setContent(rs.getString(3));
  64.         affiche.setIssueTime(rs.getString(4));
  65.       }
  66.     }
  67.     catch (SQLException ex) {
  68.     }
  69.     return affiche;
  70.   }
  71. //全部查询的方法
  72.   public List selectAffiche() {
  73.     List list = new ArrayList();
  74.     AfficheForm affiche = null;
  75.     try {
  76.       ps = connection.prepareStatement(FinalConstants.affiche_select);
  77.       ResultSet rs = ps.executeQuery();
  78.       while (rs.next()) {
  79.         affiche = new AfficheForm();
  80.         affiche.setId(Integer.valueOf(rs.getString(1)));
  81.         affiche.setName(rs.getString(2));
  82.         affiche.setContent(rs.getString(3));
  83.         affiche.setIssueTime(rs.getString(4));
  84.         list.add(affiche);
  85.       }
  86.     }
  87.     catch (SQLException ex) {
  88.     }
  89.     return list;
  90.   }
  91. }