首页>代码>Java Servlet开发的可用于java毕业设计的甜品糕点整站源码>/zuidaima_cakeshop/src/com/lovo/cq/cakeshop/daoimpl/AdminNoteDaoImpl.java
package com.lovo.cq.cakeshop.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.cakeshop.common.DbUtil; import com.lovo.cq.cakeshop.dao.AdminNoteDao; import com.lovo.cq.cakeshop.po.Inform; import com.lovo.cq.cakeshop.po.InformPager; import com.lovo.cq.cakeshop.po.Note; import com.lovo.cq.cakeshop.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; } }

hmdzmsl12 LV2
2023年10月28日
微信网友_6184005683466240 LV11
2023年6月12日
微信网友_6508798513811456 LV5
2023年6月8日
北方菜 LV11
2022年12月30日
1532593037 LV8
2022年11月23日
zhaoyangwfd LV17
2022年6月22日
kirito1994 LV5
2022年4月19日
330786215 LV14
2022年4月18日
xiaodao12 LV2
2022年2月28日
MarkLee 琥珀川 LV13
2022年1月25日

哭了跨服了莫 LV1
2024年10月16日
柳咪华沙 LV7
2024年6月29日
rain112 LV31
2024年6月18日
郭宇航裹裹 LV5
2024年6月7日
ming_123_9715 LV23
2024年5月16日
bbczlitao LV9
2024年3月5日
liiiyou LV1
2024年1月26日
a2796831202
2023年12月20日
暂无贡献等级
zzzhhhhhh7758521 LV1
2023年11月16日
hmdzmsl12 LV2
2023年10月28日