replydaoimpl.java
来自「房产交易平台 服务器端建议代码。工厂模型。」· Java 代码 · 共 107 行
JAVA
107 行
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 + =
减小字号Ctrl + -
显示快捷键?