博客
关于我
新闻发布项目——数据实现类(newsTbDaoImpl)
阅读量:586 次
发布时间:2019-03-11

本文共 4823 字,大约阅读时间需要 16 分钟。

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
getnewsTbAll() { List
newsList=new ArrayList
(); 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
prams = new ArrayList(); 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=?"; Listprams=new ArrayList(); 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=?"; Listprams=new ArrayList(); 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=?"; Listprams=new ArrayList(); 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
getnewsAllById(int id) { List
nlist=new ArrayList
(); String sql="select * from newsTb where categoryID=?"; List
prams=new ArrayList(); 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; }}

转载地址:http://jrktz.baihongyu.com/

你可能感兴趣的文章
mysql5.7 for windows_MySQL 5.7 for Windows 解压缩版配置安装
查看>>
Webpack 基本环境搭建
查看>>
mysql5.7 安装版 表不能输入汉字解决方案
查看>>
MySQL5.7.18主从复制搭建(一主一从)
查看>>
MySQL5.7.19-win64安装启动
查看>>
mysql5.7.19安装图解_mysql5.7.19 winx64解压缩版安装配置教程
查看>>
MySQL5.7.37windows解压版的安装使用
查看>>
mysql5.7免费下载地址
查看>>
mysql5.7命令总结
查看>>
mysql5.7安装
查看>>
mysql5.7性能调优my.ini
查看>>
MySQL5.7新增Performance Schema表
查看>>
Mysql5.7深入学习 1.MySQL 5.7 中的新增功能
查看>>
Webpack 之 basic chunk graph
查看>>
Mysql5.7版本单机版my.cnf配置文件
查看>>
mysql5.7的安装和Navicat的安装
查看>>
mysql5.7示例数据库_Linux MySQL5.7多实例数据库配置
查看>>
Mysql8 数据库安装及主从配置 | Spring Cloud 2
查看>>
mysql8 配置文件配置group 问题 sql语句group不能使用报错解决 mysql8.X版本的my.cnf配置文件 my.cnf文件 能够使用的my.cnf配置文件
查看>>
MySQL8.0.29启动报错Different lower_case_table_names settings for server (‘0‘) and data dictionary (‘1‘)
查看>>