notetypedao.java

来自「java带进度条上传尽量不要让站长把时间都花费在为您修正说明上」· Java 代码 · 共 136 行

JAVA
136
字号
package com.jmwl.dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.jmwl.common.BlogException;
import com.jmwl.vo.NoteTypeVO;

public class NoteTypeDAO extends BasicDAO {
	
	public boolean findNoteTypeIsExist(String noteTypename,int userid) throws BlogException{
		boolean b = false;
		String sql = "select * from note_type where note_name=? and user_id=?";
		try {
			PreparedStatement ps = this.getConn().prepareStatement(sql);
			ps.setString(1, noteTypename);
			ps.setInt(2, userid);
			ResultSet rs = ps.executeQuery();
			while(rs.next())
			{
				b = true;
			}
			return b;
		} catch (SQLException e) {
			throw new BlogException("对不起,查询日志类型是否存在时出现错误");
		}
	}
	
	
	public void addNoteType(String noteTypename,int userid) throws BlogException{
		String sql = "insert into note_type(note_name,user_id) values(?,?)";
		try {
			PreparedStatement ps = this.getConn().prepareStatement(sql);
			ps.setString(1, noteTypename);
			ps.setInt(2, userid);
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new BlogException("对不起,添加日志类型出现错误");
		}
	}
	
	public List<NoteTypeVO> findAllNoteType(int userid) throws BlogException {
		List<NoteTypeVO> list = new ArrayList<NoteTypeVO>();
		String sql = "select * from note_type where user_id=?";
		try {
			PreparedStatement ps = this.getConn().prepareStatement(sql);
			ps.setInt(1, userid);
			ResultSet rs = ps.executeQuery();
			while(rs.next())
			{
				NoteTypeVO vo = new NoteTypeVO();
				vo.setUserid(rs.getInt("user_id"));
				vo.setNotename(rs.getString("note_name"));
				vo.setNoteTypeid(rs.getInt("id"));
				list.add(vo);
			}
			return list;
		} catch (SQLException e) {
			throw new BlogException("对不起,查询所有日志类型出现错误");
		}
	}
	
	public void updateNoteType(int notetypeid,String noteTypename) throws BlogException
	{
		String sql = "update note_type set note_name = ? where id = ?";
		PreparedStatement ps;
		try {
			ps = this.getConn().prepareStatement(sql);
			ps.setString(1, noteTypename);
			ps.setInt(2, notetypeid);
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new BlogException("对不起,修改日志类型出现错误");
		}
	}
	
	public boolean findNoteByNoteType(int notetypeid) throws BlogException{
		boolean b = false;
		String sql = "select * from note where note_type_id = ?";
		PreparedStatement ps;
		try {
			ps = this.getConn().prepareStatement(sql);
			ps.setInt(1, notetypeid);
			ResultSet rs = ps.executeQuery();
			while(rs.next())
				b  = true;
			return b;
		} catch (SQLException e) {
			throw new BlogException("对不起,根据日志类型查找日志错误");
		}
		
	}
	
	
	public void delNoteType(int notetypeid) throws BlogException
	{
		String sql = "delete from note_type where id = ?";
		PreparedStatement ps;
		try {
			ps = this.getConn().prepareStatement(sql);
			ps.setInt(1, notetypeid);
			ps.executeUpdate();
		} catch (SQLException e) {
			throw new BlogException("对不起,日志类型删除错误");
		}
	}
	
	public NoteTypeVO findNotetypeByid(int id) throws BlogException
	{
		String sql = "select * from note_type where id = ?";
		PreparedStatement ps;
		try {
			ps = this.getConn().prepareStatement(sql);
			ps.setInt(1, id);
			ResultSet rs = ps.executeQuery();
			NoteTypeVO vo = null;
			while(rs.next())
			{
				vo = new NoteTypeVO();
				vo.setUserid(rs.getInt("user_id"));
				vo.setNotename(rs.getString("note_name"));
				vo.setNoteTypeid(rs.getInt("id"));
			}
			return vo;
		} catch (SQLException e) {
			throw new BlogException("对不起,日志类型删除错误");
		}
		
	}
	
	
}

⌨️ 快捷键说明

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