新闻发布项目——数据实现类(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;
	}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

穆雄雄

哎,貌似还没开张来着呢~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值