博客
关于我
新闻发布项目——数据实现类(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/

你可能感兴趣的文章
Mysql_Postgresql中_geometry数据操作_st_astext_GeomFromEWKT函数_在java中转换geometry的16进制数据---PostgreSQL工作笔记007
查看>>
mysql_real_connect 参数注意
查看>>
mysql_secure_installation初始化数据库报Access denied
查看>>
MySQL_西安11月销售昨日未上架的产品_20161212
查看>>
Mysql——深入浅出InnoDB底层原理
查看>>
MySQL“被动”性能优化汇总
查看>>
MySQL、HBase 和 Elasticsearch:特点与区别详解
查看>>
MySQL、Redis高频面试题汇总
查看>>
MYSQL、SQL Server、Oracle数据库排序空值null问题及其解决办法
查看>>
mysql一个字段为空时使用另一个字段排序
查看>>
MySQL一个表A中多个字段关联了表B的ID,如何关联查询?
查看>>
MYSQL一直显示正在启动
查看>>
MySQL一站到底!华为首发MySQL进阶宝典,基础+优化+源码+架构+实战五飞
查看>>
MySQL万字总结!超详细!
查看>>
Mysql下载以及安装(新手入门,超详细)
查看>>
MySQL不会性能调优?看看这份清华架构师编写的MySQL性能优化手册吧
查看>>