picturereviewdao.java

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

JAVA
229
字号
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.dto.PictureReviewDTO;
import com.jmwl.vo.PictureReviewVO;

public class PictureReviewDAO extends BasicDAO {

	PreparedStatement ps;
	ResultSet rs;

	/**
	 * 添加新的回复
	 * @param dto
	 * @return
	 * @throws BlogException
	 */
	public boolean new_Review(PictureReviewDTO dto) throws BlogException 
	{
		boolean b = true;
		String sql = "insert into picture_reviews(picture_id,content,pub_time,user_id,username) values(?,?,?,?,?);";
		try {
			ps = this.getConn().prepareStatement(sql);
			ps.setInt(1, dto.getPicture_id());
			ps.setString(2, dto.getContent());
			ps.setString(3, dto.getPub_time());
			ps.setInt(4, dto.getUser_id());
			ps.setString(5, dto.getUsername());
			ps.executeUpdate();
		} catch (SQLException e) {
			b = false;
			throw new BlogException("回复失败,数据库出现异常");
		}
		return b;
	}
	
	
	/**
	 * 查询某条回复
	 * @param rid
	 * @return
	 * @throws BlogException
	 */
	public List select_Review(int rid) throws BlogException
	{
		List list = new ArrayList();
		String sql = "select * from picture_reviews where id=?";
		try {
			ps = this.getConn().prepareStatement(sql);
			ps.setInt(1, rid);
			rs = ps.executeQuery();
			while(rs.next())
			{
				PictureReviewVO vo = new PictureReviewVO();
				vo.setId(rs.getInt(1));
				vo.setPicture_id(rs.getInt(2));
				vo.setContent(rs.getString(3));
				vo.setPub_time(rs.getString(4));
				vo.setUser_id(rs.getInt(5));
				list.add(vo);
			}
		} catch (SQLException e) {
			throw new BlogException("查询失败,数据库出错!");
		}
		return list;
	}
	/**
	 * 修改某条回复
	 * @return
	 * @throws BlogException 
	 */
	public boolean update_Review(String content,int rid) throws BlogException
	{
		boolean b = true;
		String sql = "update picture_reviews set content=? where id=?";
		try {
			ps = this.getConn().prepareStatement(sql);
			ps.setString(1, content);
			ps.setInt(2, rid);
			ps.executeUpdate();
		} catch (SQLException e) {
			b = false;
			throw new BlogException("修改回复失败!数据库出错!");
		}
		return b;
	}
	
	/**
	 * 删除某条回复
	 * @param rid
	 * @return
	 * @throws BlogException
	 */
	public boolean del_Review(int rid) throws BlogException
	{
		boolean b = true;
		String sql = "delete from picture_reviews where id=?";
		try {
			ps = this.getConn().prepareStatement(sql);
			ps.setInt(1, rid);
			ps.executeUpdate();
		} catch (SQLException e) {
			b = false;
			throw new BlogException("删除失败!数据库出错!");
		}
		return b;
	}
	
	/**
	 * 删除某个相片的所有回复
	 * @param rid
	 * @return
	 * @throws BlogException
	 */
	public boolean del_picture_Review(int pid) throws BlogException
	{
		boolean b = true;
		String sql = "delete from picture_reviews where picture_id=?";
		try {
			ps = this.getConn().prepareStatement(sql);
			ps.setInt(1, pid);
			ps.executeUpdate();
		} catch (SQLException e) {
			b = false;
			throw new BlogException("删除失败!数据库出错!");
		}
		return b;
	}
	
	/**
	 * 修改主人季语
	 * @param content
	 * @param rid
	 * @return
	 * @throws BlogException
	 */
	public boolean update_host_answer(String content,int rid) throws BlogException
	{
		boolean b = true;
		String sql = "update picture_reviews set host_answer=? where id=?";
		try {
			ps = this.getConn().prepareStatement(sql);
			ps.setString(1, content);
			ps.setInt(2, rid);
			ps.executeUpdate();
		} catch (SQLException e) {
			b = false;
			e.printStackTrace();
			throw new BlogException("修改回复失败!数据库出错!");
		}
		return b;
	}
	
	/**
	 * 屏蔽回复
	 * @param rid
	 * @return
	 * @throws BlogException
	 */
	public boolean forbid_Reviews(int rid) throws BlogException
	{
		boolean b = true;
		String sql = "update picture_reviews set content=? where id=?";
		try {
			System.out.println(rid+"     ---------------");
			ps = this.getConn().prepareStatement(sql);
			ps.setString(1, "该用户的发言被已被管理员屏蔽");
			ps.setInt(2, rid);
			ps.executeUpdate();
		} catch (SQLException e) {
			b = false;
			e.printStackTrace();
			throw new BlogException("屏蔽回复失败,数据库出错!");
		}
		return b;
	}
	
	public List sele_picture_Reviews(int pid) throws BlogException
	{
		List list = new ArrayList();
		String sql = "select * from picture_reviews where picture_id=? order by id desc";
		try {
			ps = this.getConn().prepareStatement(sql);
			ps.setInt(1, pid);
			rs = ps.executeQuery();
			while(rs.next())
			{
				PictureReviewVO vo = new PictureReviewVO();
				vo.setId(rs.getInt(1));
				vo.setPicture_id(rs.getInt(2));
				vo.setContent(rs.getString(3));
				vo.setPub_time(rs.getString(4));
				vo.setUser_id(rs.getInt(5));
				vo.setHost_answer(rs.getString(6));
				vo.setUsername(rs.getString(7));
				list.add(vo);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new BlogException("查询回复失败,数据库出错!");
		}
		return list;
	}
	
	public int getPictureId(int rid) throws BlogException
	{
		int pid = 0;
		String sql = "select picture_id from picture_reviews where id=?";
		try {
			ps = this.getConn().prepareStatement(sql);
			ps.setInt(1, rid);
			rs = ps.executeQuery();
			while(rs.next())
			{
				pid = rs.getInt(1);
			}
		} catch (SQLException e) {
			throw new BlogException("查询相片ID失败!");
		}
		return pid;
	}
}

⌨️ 快捷键说明

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