首页>代码>Spring MVC+Servlet开发的糖果电子商务类整站源码,可用于java毕业设计>/zuidaima_beneny_candy/src/com/lovo/cq/candy/daoimpl/AdminNoteDaoImpl.java
package com.lovo.cq.candy.daoimpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.lovo.cq.candy.common.DbUtil;
import com.lovo.cq.candy.dao.AdminNoteDao;
import com.lovo.cq.candy.po.Inform;
import com.lovo.cq.candy.po.InformPager;
import com.lovo.cq.candy.po.Note;
import com.lovo.cq.candy.po.NotePager;

public class AdminNoteDaoImpl implements AdminNoteDao {

	public List getAllNotes() {
		List noteList = new ArrayList();
		DbUtil dao = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		String sql = "select * from tb_note";
		try {
			dao = new DbUtil();
			ps = dao.getCon().prepareStatement(sql);
			rs = ps.executeQuery();
			while (rs.next()) {
				Note note = new Note();
				note.setId(rs.getInt("id"));
				note.setTitle(rs.getString("title"));
				note.setAuthor(rs.getString("author"));
				note.setContent(rs.getString("content"));
				note.setLy_time(rs.getString("ly_time"));
				noteList.add(note);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				rs.close();
				ps.close();
				dao.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return noteList;
	}

	public boolean deleteNote(int[] ids) {
		System.out.print(ids);
		DbUtil daoUtil = null;
		PreparedStatement ps = null;
		Connection conn = null;
		String sql = "delete from tb_note where id=?";
		try {
			daoUtil = new DbUtil();
			conn = daoUtil.getCon();
			conn.setAutoCommit(false);
			ps = conn.prepareStatement(sql);
			for(int j=0;j<ids.length;j++) {
				ps.setInt(1, ids[j]);
				ps.addBatch();
			}
			int[] k = ps.executeBatch();
			conn.commit();
			if(k.length == ids.length) {
				return true;
			}
		} catch (Exception e) {
			try {
				conn.rollback();
			} catch (Exception ex) {
				ex.printStackTrace();
			}
		} finally {
			try {
				ps.close();
				daoUtil.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return false;
	}

	public NotePager getNotePager(int index, int pageSize) {
		Map noteMap = new HashMap();
		DbUtil db = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			db = new DbUtil();
			String sql = "select * from tb_note limit ?,?";
			ps = db.getCon().prepareStatement(sql);
			ps.setInt(1, index);
			ps.setInt(2, pageSize);
			rs = ps.executeQuery();
			while(rs.next()) {
				Note note = new Note();
				note.setId(rs.getInt("id"));
				note.setAuthor(rs.getString("author"));
				note.setTitle(rs.getString("title"));
				note.setContent(rs.getString("content"));
				note.setLy_time(rs.getString("ly_time"));
				note.setImgs(rs.getString("imgs"));
				noteMap.put(note.getId(), note);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				rs.close();
				ps.close();
				db.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		NotePager np = new NotePager();
		np.setNoteMap(noteMap);
		np.setPageSize(pageSize);
		np.setTotalNum(getAllNotes().size());
		return np;
	}

}
最近下载更多
information  LV2 2023年4月28日
姜广坤  LV14 2023年1月5日
xierhui  LV6 2022年9月20日
330786215  LV14 2022年4月18日
lzlzyw  LV14 2022年3月25日
暖光女神  LV11 2022年2月9日
MarkLee 琥珀川  LV13 2022年1月21日
1207748096  LV6 2021年5月12日
怀树7777  LV5 2021年3月29日
不停的奔跑  LV20 2021年3月21日
最近浏览更多
liiiyou  LV1 1月26日
爱吃零食  LV1 1月4日
微信网友_6680567232876544  LV8 2023年10月22日
gann2015  LV24 2023年10月21日
15066671558 2023年10月10日
暂无贡献等级
lightg  LV3 2023年7月27日
暂无贡献等级
Merdan_810 2023年6月9日
暂无贡献等级
information  LV2 2023年4月28日
微信网友_6438918626938880  LV1 2023年4月19日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友