首页>代码>jsp+servlet+c3p0开发传智播客电子书城项目源码,包含ppt>/(2019-5-16,第二个项目)传智书城项目资料汇总/(项目源码)itcaststore/src/cn/itcast/itcaststore/dao/NoticeDao.java
package cn.itcast.itcaststore.dao;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import cn.itcast.itcaststore.domain.Notice;
import cn.itcast.itcaststore.utils.DataSourceUtils;

public class NoticeDao {
	//后台系统,查询所有的公告
	public List<Notice> getAllNotices() throws SQLException {
		String sql = "select * from notice order by n_time desc limit 0,10";
		QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
		return runner.query(sql, new BeanListHandler<Notice>(Notice.class));
	}

	//后台系统,添加公告
	public void addNotice(Notice n) throws SQLException {
		String sql = "insert into notice(title,details,n_time) values(?,?,?)";
		QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
		runner.update(sql, n.getTitle(),n.getDetails(),n.getN_time());
	}

	//后台系统,根据id查找公告
	public Notice findNoticeById(String n_id) throws SQLException {
		String sql = "select * from notice where n_id = ?";
		QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
		return runner.query(sql, new BeanHandler<Notice>(Notice.class),n_id);
	}

	//后台系统,根据id修改单个公告
	public void updateNotice(Notice n) throws SQLException {
		String sql = "update notice set title=?,details=?,n_time=? where n_id=?";
		QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
		runner.update(sql, n.getTitle(),n.getDetails(),n.getN_time(),n.getN_id());
	}

	//后台系统,根据id删除公告
	public void deleteNotice(String n_id) throws SQLException {
		String sql = "delete from notice where n_id = ?";
		QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
		runner.update(sql, n_id);
	}

	//前台系统,查询最新添加或修改的一条公告
	public Notice getRecentNotice() throws SQLException {
		String sql = "select * from notice order by n_time desc limit 0,1";
		QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
		return runner.query(sql, new BeanHandler<Notice>(Notice.class));
	}
}
最近下载更多
周敏国  LV9 2023年8月19日
Gjc175636312  LV2 2023年4月20日
xiaoadmin  LV1 2023年1月29日
Jiang_jiang5  LV1 2023年1月9日
zxwzxwz  LV2 2023年1月2日
Ada-Lilith  LV1 2022年12月7日
zsj45655  LV1 2022年10月4日
ldm654123  LV3 2022年10月1日
18356557758  LV5 2022年9月15日
onemee  LV36 2022年7月31日
最近浏览更多
Yuan_yuan 1月9日
暂无贡献等级
VOEeee 2024年12月17日
暂无贡献等级
暂无贡献等级
zolscy  LV24 2024年11月28日
Yizhuo007 2024年11月26日
暂无贡献等级
ehui33 2024年11月24日
暂无贡献等级
韩同学 2024年11月23日
暂无贡献等级
微信网友_7257882016698368 2024年11月17日
暂无贡献等级
gaochenjun 2024年10月23日
暂无贡献等级
123wwwghh  LV2 2024年9月18日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友