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

📄 replydaoimpl.java

📁 房产交易平台 服务器端建议代码。工厂模型。
💻 JAVA
字号:
package com.fc.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.fc.dao.conn.DBConn;

public class ReplyDaoImpl implements ReplyDao {
	public ReplyDaoImpl() {
	}

	/* (non-Javadoc)
	 * @see com.fc.dao.ReplyDao#findByPID(com.fc.dao.Pubs)
	 */
	public Reply findByPID(Reply reply) {
		Connection conn = null;
		PreparedStatement prst = null;
		ResultSet rs = null;
		Reply rep = null;
		try {
			conn = DBConn.getConnection();
			prst = conn
					.prepareStatement("select id,pid,bid,msg from reply where pid=?");
			prst.setLong(1, reply.getPid());
			rs = prst.executeQuery();
			if (rs.next()) {
				rep = new Reply();
				rep.setId(rs.getInt(1));
				rep.setPid(rs.getLong(2));
				rep.setBid(rs.getLong(3));
				rep.setMsg(rs.getString(4));
			}
		} catch (SQLException ea) {
			ea.printStackTrace();
		} finally {
			if (conn != null)
				try {
					conn.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
		}
		return rep;

	}
	
	/* (non-Javadoc)
	 * @see com.fc.dao.ReplyDao#save(com.fc.dao.Reply)
	 */
	public boolean save(Reply rep){
		Connection conn = null;
		PreparedStatement prst = null;
		boolean ok=false;
		try {
			conn = DBConn.getConnection();
			prst = conn
					.prepareStatement("insert into reply (pid,bid,msg)values(?,?,?)");
			prst.setLong(1, rep.getPid());
			prst.setLong(2, rep.getBid());
			prst.setString(3, rep.getMsg());
			prst.execute();
			ok=true;
		} catch (SQLException ea) {
			ea.printStackTrace();
		} finally {
			if (conn != null)
				try {
					conn.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
		}
		return ok;

	}
	
	/* (non-Javadoc)
	 * @see com.fc.dao.ReplyDao#remove(com.fc.dao.Reply)
	 */
	public boolean remove(Reply rep){
		Connection conn = null;
		PreparedStatement prst = null;
		boolean ok=false;
		try {
			conn = DBConn.getConnection();
			prst = conn
					.prepareStatement("delete from reply where id=?)");
			prst.setLong(1, rep.getId());
			prst.execute();
			ok=true;
		} catch (SQLException ea) {
			ea.printStackTrace();
		} finally {
			if (conn != null)
				try {
					conn.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
		}
		return ok;

	}
}

⌨️ 快捷键说明

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