⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 notedaoimpl.java

📁 实现复杂份的分页功能
💻 JAVA
字号:
package com.nokoyo.ec.impl;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.nikoyo.ec.dao.NoteDAO;
import com.nikoyo.ec.vo.Note;
import com.nokoyo.ec.dbc.DataBaseConnection;

public class NoteDAOImpl implements NoteDAO {

	private DataBaseConnection dbc = null;

	public NoteDAOImpl() {
		this.dbc = new DataBaseConnection();

	}

	public Boolean doCreate(Note note) {

		Boolean flag = false;
		String sql = "insert into note(title,author,content) values(?,?,?);";
		PreparedStatement pstmt = null;

		try {
			pstmt = this.dbc.getConnection().prepareStatement(sql);
			pstmt.setString(1, note.getTitle());
			pstmt.setString(2, note.getAuthor());
			pstmt.setString(2, note.getContent());
			pstmt.execute();
			pstmt.close();
			flag = true;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {

		}

		return flag;
	}

	
	
	
	public int doCreateList(List notes) throws Exception {
		int count = 0;

		boolean flag = false;
		this.dbc.getConnection().setAutoCommit(false);
		
		Iterator iter = notes.iterator();
		Note note = null;
		while (iter.hasNext()) {
			note = (Note) iter.next();
			if (!this.doCreate(note)) {
				flag = false;
				break;

			}
		}

		if (flag) {
			this.dbc.getConnection().commit();
		} else {
			this.dbc.getConnection().rollback();

		}

		this.dbc.close();
		return count;
	}
	
	
	public boolean doUpdate(Note note) throws Exception {
		Boolean flag = false;
		String sql = "update  note set title =?,author=?,content=? where id = ?;";
		PreparedStatement pstmt = null;

		try {
			pstmt = this.dbc.getConnection().prepareStatement(sql);
			pstmt.setString(1, note.getTitle());
			pstmt.setString(2, note.getAuthor());
			pstmt.setString(2, note.getContent());
			pstmt.setInt(4, note.getId());
			pstmt.executeUpdate();
			pstmt.close();
			flag = true;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {

		}

		return flag;
	}
	
	
	public int doUpdateList(List notes) throws Exception {
		int count = 0;

		boolean flag = false;
		this.dbc.getConnection().setAutoCommit(false);
		
		Iterator iter = notes.iterator();
		Note note = null;
		while (iter.hasNext()) {
			note = (Note) iter.next();
			if (!this.doUpdate(note)) {
				flag = false;
				break;

			}
		}

		if (flag) {
			this.dbc.getConnection().commit();
		} else {
			this.dbc.getConnection().rollback();

		}

		this.dbc.close();
		return count;
	}

	
	
	public boolean doRemove(int id) throws Exception {
		Boolean flag = false;
		String sql = "delete from note where id = ?;";
		PreparedStatement pstmt = null;

		try {
			pstmt = this.dbc.getConnection().prepareStatement(sql);
			
			pstmt.setInt(1, id);
			pstmt.execute();
			pstmt.close();
			flag = true;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {

		}

		return flag;
		
	}

	public int doRemoveList(String[] ids) throws Exception {
		int count = 0;

		boolean flag = false;
		this.dbc.getConnection().setAutoCommit(false);
		
		Note note = null;
		for (int i = 0; i < ids.length; i++) {
			if (!this.doRemove(Integer.getInteger(ids[i]))){
				flag = true;
				break;
			}
		}
		

		if (flag) {
			this.dbc.getConnection().commit();
		} else {
			this.dbc.getConnection().rollback();

		}

		this.dbc.close();
		
		return count;
	}

	

	public List findAll(int startRow, int endRow, Map sortValueMap,
			Map filterPropertyMap) throws Exception {
		
		
		
		return null;
	}



}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -