博客
关于我
新闻发布项目——数据实现类(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 server has gone away
查看>>
mysql skip-grant-tables_MySQL root用户忘记密码怎么办?修改密码方法:skip-grant-tables
查看>>
mysql slave 停了_slave 停止。求解决方法
查看>>
MySQL SQL 优化指南:主键、ORDER BY、GROUP BY 和 UPDATE 优化详解
查看>>
MYSQL sql语句针对数据记录时间范围查询的效率对比
查看>>
mysql sum 没返回,如果没有找到任何值,我如何在MySQL中获得SUM函数以返回'0'?
查看>>
mysql sysbench测试安装及命令
查看>>
mysql Timestamp时间隔了8小时
查看>>
Mysql tinyint(1)与tinyint(4)的区别
查看>>
MySQL Troubleshoting:Waiting on query cache mutex
查看>>
mysql union orderby 无效
查看>>
mysql v$session_Oracle 进程查看v$session
查看>>
mysql where中如何判断不为空
查看>>
MySQL Workbench 使用手册:从入门到精通
查看>>
MySQL Workbench 数据库建模详解:从设计到实践
查看>>
MySQL Workbench 数据建模全解析:从基础到实践
查看>>
mysql workbench6.3.5_MySQL Workbench
查看>>
MySQL Workbench安装教程以及菜单汉化
查看>>
MySQL Xtrabackup 安装、备份、恢复
查看>>
mysql [Err] 1436 - Thread stack overrun: 129464 bytes used of a 286720 byte stack, and 160000 bytes
查看>>