新闻发布项目——数据实现类(newsTbDaoImpl)

简介: 新闻发布项目——数据实现类(newsTbDaoImpl)
package bdqn.newsMange.Dao.Impl;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import bdqn.newsMange.Dao.BaseDao;
import bdqn.newsMange.Dao.newsTbDao;
import bdqn.newsMange.entity.newsTb;
/**
 * 新闻的实现类
 * @author Administrator
 *
 */
public class newsTbDaoImpl extends BaseDao implements newsTbDao {
  //查询
  public List<newsTb> getnewsTbAll() {
    List<newsTb> newsList=new ArrayList<newsTb>();
    String sql="select * from newsTb";
    try {
      ResultSet rs=executeQurey(sql, null);
      while(rs.next()){
        newsTb ne=new newsTb();
        ne.setNewsID(rs.getInt("newsid"));
        ne.setTitle(rs.getString("title"));
        ne.setAuthor(rs.getString("author"));
        ne.setCreateDate(rs.getDate("CreateDate"));
        ne.setCategoryID(rs.getInt("CategoryID"));
        ne.setContent(rs.getString("Content"));
        ne.setModifyDate(rs.getDate("ModifyDate"));
        ne.setPicPath(rs.getString("PicPath"));
        ne.setSummary(rs.getString("Summary"));
        newsList.add(ne);
      }
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }finally{
      closeAll();
    }
    return newsList;
  }
  //添加
  public int addNewsTb(newsTb news) {
    int rel = 0;
    List<Object> prams = new ArrayList<Object>();
    String sql = "insert newsTb(categoryID,summary,title,"
        + "content,picPath,author,createDate,modifyDate) values(?,?,?,?,?,?,?,?)";
    prams.add(news.getCategoryID());
    prams.add(news.getSummary());
    prams.add(news.getTitle());
    prams.add(news.getContent());
    prams.add(news.getPicPath());
    prams.add(news.getAuthor());
    prams.add(news.getCreateDate());
    prams.add(news.getModifyDate());
    try {
      rel=executeUpdate(sql, prams);
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }finally{
      closeAll();
    }
    return rel;
  }
  //修改
  public int updateNewsTb(newsTb news) {
    int rel=0;
    String sql="update newsTb set categoryID=?,summary=?,title=?,"
        + "content=?,picPath=?,author=?,createDate=?,modifyDate=? where newsID=?";
    List<Object>prams=new ArrayList<Object>();
    prams.add(news.getCategoryID());
    prams.add(news.getSummary());
    prams.add(news.getTitle());
    prams.add(news.getContent());
    prams.add(news.getPicPath());
    prams.add(news.getAuthor());
    prams.add(news.getCreateDate());
    prams.add(news.getModifyDate());
    prams.add(news.getNewsID());
    try {
      rel=executeUpdate(sql, prams);
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }finally{
      closeAll();
    }
    return rel;
  }
  //删除
  public int addNewsTb(int id) {
    int rel=0;
    String sql="delete from newsTb where newsID=?";
    List<Object>prams=new ArrayList<Object>();
    prams.add(id);
    try {
      rel=executeUpdate(sql, prams);
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return rel;
  }
  //根据新闻的id查询新闻的信息
  public newsTb getAllNewsById(int id) {
    String sql="select * from newsTb where newsID=?";
    List<Object>prams=new ArrayList<Object>();
    prams.add(id);
    newsTb news=null;
    try {
      ResultSet rs=executeQurey(sql, prams);
      if(rs.next()){
        news=new newsTb();
        news.setNewsID(rs.getInt("newsid"));
        news.setTitle(rs.getString("title"));
        news.setAuthor(rs.getString("author"));
        news.setCreateDate(rs.getDate("CreateDate"));
        news.setCategoryID(rs.getInt("CategoryID"));
        news.setContent(rs.getString("Content"));
        news.setModifyDate(rs.getDate("ModifyDate"));
        news.setPicPath(rs.getString("PicPath"));
        news.setSummary(rs.getString("Summary"));
      }
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }finally{
      closeAll();
    }
    return news;
  }
  //根据类别id查询新闻的信息
  public List<newsTb> getnewsAllById(int id) {
    List<newsTb> nlist=new ArrayList<newsTb>();
    String sql="select * from newsTb where categoryID=?";
    List<Object>prams=new ArrayList<Object>();
    prams.add(id);
    try {
      ResultSet rs=executeQurey(sql, prams);
      newsTb news=null;
      while(rs.next()){
        news=new newsTb();
        news.setNewsID(rs.getInt("newsid"));
        news.setTitle(rs.getString("title"));
        news.setAuthor(rs.getString("author"));
        news.setCreateDate(rs.getDate("CreateDate"));
        news.setCategoryID(rs.getInt("CategoryID"));
        news.setContent(rs.getString("Content"));
        news.setModifyDate(rs.getDate("ModifyDate"));
        news.setPicPath(rs.getString("PicPath"));
        news.setSummary(rs.getString("Summary"));
        nlist.add(news);
      }
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }finally{
      closeAll();
    }
    return nlist;
  }
}
相关文章
|
11月前
Watcher机制(三)之ZooKeeper
Watcher机制(三)之ZooKeeper
136 1
Watcher机制(三)之ZooKeeper
|
负载均衡 安全 网络协议
突发!亚洲游戏行业遭遇史上最大黑客 DDoS 攻击
游戏行业遭受频繁DDoS攻击,导致服务中断,例如欧洲国家安道尔全国近断网半小时。黑客利用低成本的DDoS手段勒索,尤其是针对中日韩印的手游市场。最常见的攻击方式是UDP洪水。防御措施包括使用硬件防火墙、抗D盾、负载均衡、SCDN流量清洗和分布式集群防御。游戏公司需平衡成本与安全,以确保服务稳定和玩家体验。在中国,此类攻击属犯罪行为,最高可判处有期徒刑。
Java系列之:字符串的截取及分割 split() 和 substring()
这篇文章通过示例代码讲解了Java中字符串的截取和分割操作,包括使用`split()`方法根据正则表达式进行字符串分割以及使用`substring()`方法进行字符串截取的不同使用方式及其输出结果。
Java系列之:字符串的截取及分割 split() 和 substring()
|
网络协议 Linux
Cannot assign requested address解决办法
Cannot assign requested address解决办法
|
Kubernetes 监控 API
【K8S系列】深入解析 ReplicaSet
【K8S系列】深入解析 ReplicaSet
707 1
|
消息中间件 关系型数据库 Kafka
TiDB实时同步数据到PostgreSQL(一) ---- 搭建kafka集群
TiDB实时同步数据到PostgreSQL的第一篇,主要介绍kafka集群的搭建。
|
运维 Ubuntu 关系型数据库
使用kettle采集excel表格中的数据
使用kettle采集excel表格中的数据
|
数据采集 编解码 监控
网站性能指标设计详解
网站性能指标设计详解
522 0
网站性能指标设计详解
|
存储 前端开发 安全
4-SpringSecurity:CSRF防护
4-SpringSecurity:CSRF防护
412 0
4-SpringSecurity:CSRF防护
|
Kubernetes 关系型数据库 API
初试 Kubernetes 集群中使用 Contour 反向代理
在 Kubernetes 中运行大规模以 Web 为中心的工作负载,最关键的需求之一就是在 L7 层实现高效流畅的入口流量管理。自从第一批 Kubernetes Ingress Controller 开发完成以来,Envoy(由 Matt Klein 和 Lyft 团队开发)已经成为云原生生态系统中的新生力量。
2401 0