/*
* s2jsp.lg.dao.impl.ReplyDaoImpl.java
* 2007-7-19
* ReplyDao的实现类
*/
package s2jsp.lg.dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import s2jsp.lg.dao.ReplyDao;
import s2jsp.lg.entity.Reply;
public class ReplyDaoImpl extends BaseDao implements ReplyDao {
private Connection conn = null; // 保存数据库连接
private PreparedStatement pstmt = null; // 用于执行SQL语句
private ResultSet rs = null ; // 用户保存查询结果集
/**
* 添加回复
* @param reply
* @return 增加条数
*/
public int addReply(Reply reply) {
String sql = "insert into TBL_REPLY(title,content,publishTime,modifyTime,uId,topicId) values(?,?,?,?," + reply.getUid() + "," + reply.getTopicId() + ")";
String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); // 取得日期时间
String[] parm = { reply.getTitle(), reply.getContent(), time, time };
return this.executeSQL(sql, parm); // 执行sql,并返回影响行数
}
/**
* 删除回复
* @param replyId
* @return 删除条数
*/
public int deleteReply(int replyId) {
String sql = "delete from TBL_REPLY where replyId=" + replyId;
return this.executeSQL(sql, null); // 执行sql,并返回影响行数
}
/**
* 更新回复
* @param reply
* @return 更新条数
*/
public int updateReply(Reply reply) {
String sql = "update TBL_REPLY set title=?, content=?, modifyTime=? where replyId="+reply.getReplyId();
String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); // 取得日期时间
String[] parm = { reply.getTitle(), reply.getContent(), time };
return this.executeSQL(sql, parm); // 执行sql,并返回影响行数
}
/**
* 查找回复List
* @param page
* @return 查询结果
*/
public List findListReply(int page, int topicId) {
List list = new ArrayList(); // 用来保存回复对象列表
conn = null; // 用于保存数据库连接
pstmt = null; // 用于执行SQL语句
rs = null; // 用户保存查询结果集
int rowBegin = 0; // 开始行数,表示每页第一条记录在数据库中的行数
if( page > 1 ) {
rowBegin = 10 * (page-1); // 按页数取得开始行数,设每页可以显示10条回复
}
try {
conn = this.getConn(); // 得到数据库连接
String sql = "select top 10 * from TBL_REPLY where topicId=" + topicId + " and replyId not in(select top "+ rowBegin + " replyId from TBL_REPLY where topicId=" + topicId + "order by publishTime )order by publishTime";
pstmt = conn.prepareStatement(sql); // 得到PreparedStatement对象
rs = pstmt.executeQuery(); // 执行sql取得结果集
/* 循环将回复信息封装成List */
while ( rs.next() ) {
Reply reply = new Reply(); // 回复对象
reply.setReplyId(rs.getInt("replyId"));
reply.setTitle(rs.getString("title"));
reply.setContent(rs.getString("content"));
reply.setPublishTime(rs.getString("publishTime"));
reply.setModifyTime(rs.getString("modifyTime"));
reply.setTopicId(rs.getInt("topicId"));
reply.setUid(rs.getInt("uId"));
list.add(reply);
}
} catch (Exception e) {
e.printStackTrace(); // 处理异常
} finally {
this.closeAll(conn, pstmt, rs); // 释放资源
}
return list;
}
/**
* 根据主题id查询出该主题的回复条数
* @param topicId 主题id
* @return 回复条数
*/
public int findCountReply(int topicId){
int count = 0; // 回复条数
Connection conn = null; // 用于保存数据库连接
PreparedStatement pstmt = null; // 用于执行SQL语句
ResultSet rs = null; // 用户保存查询结果集
String sql = "select count(*) from TBL_REPLY where topicId=" + topicId;
try {
conn = this.getConn();
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while( rs.next() ) {
count = rs.getInt(1);
}
} catch ( Exception e) {
e.printStackTrace(); // 处理异常
} finally {
this.closeAll(conn, pstmt, rs); // 释放资源
}
return count;
}
/**
* 根据主题id,查找回复的信息
* @param replyId
* @return 回复
*/
public Reply findReply(int replyId) {
String sql = "select * from TBL_REPLY where replyId=?";
Reply reply = null;
try {
conn = this.getConn(); // 获得数据库连接
pstmt = conn.prepareStatement(sql); // 得到一个PreparedStatement对象
pstmt.setInt(1, replyId); // 设置topicId为参数值
rs = pstmt.executeQuery(); // 执行sql,取得查询结果集
/* 将结果集中的信息取出保存到reply对象中,循环最多只会执行一次 */
while ( rs.next() ) {
reply = new Reply(); // 回复对象
reply.setReplyId(rs.getInt("replyId"));
reply.setTitle(rs.getString("title"));
reply.setContent(rs.getString("content"));
reply.setPublishTime(rs.getString("publishTime"));
reply.setModifyTime(rs.getString("modifyTime"));
reply.setUid(rs.getInt("uId"));
}
} catch (Exception e) {
e.printStackTrace(); // 处理异常
} finally {
this.closeAll(conn, pstmt, rs); // 释放资源
}
return reply;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
JSP BBS论坛 源码+数据库
共75个文件
gif:20个
class:15个
java:15个
5星 · 超过95%的资源 需积分: 16 38 下载量 92 浏览量
2012-10-25
10:55:40
上传
评论 2
收藏 507KB RAR 举报
温馨提示
JSP BBS论坛 实现了主页面的自动分类,可以回复帖子,查看帖子的基本功能
资源推荐
资源详情
资源评论
收起资源包目录
BBS.rar (75个子文件)
BBS
src
s2jsp
lg
entity
Board.java 979B
Topic.java 2KB
Tip.java 3KB
Reply.java 901B
User.java 2KB
dao
TopicDao.java 1KB
impl
UserDaoImpl.java 4KB
BoardDaoImpl.java 4KB
ReplyDaoImpl.java 6KB
BaseDao.java 3KB
TopicDaoImpl.java 6KB
BoardDao.java 461B
ReplyDao.java 1KB
UserDao.java 816B
test
test.java 575B
.classpath 451B
DBdata
bbs_Data.MDF 1.94MB
bbs_Log.LDF 1024KB
.mymetadata 282B
.settings
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.name 6B
.jsdtscope 500B
org.eclipse.jdt.core.prefs 330B
.myeclipse
.project 1KB
WebRoot
style
style.css 3KB
META-INF
MANIFEST.MF 36B
update.html 2KB
list.jsp 4KB
reguser.jsp 3KB
index.jsp 3KB
detail.html 3KB
login.jsp 2KB
image
board.gif 712B
topic.gif 311B
head
1.gif 4KB
7.gif 3KB
5.gif 4KB
15.gif 3KB
2.gif 4KB
12.gif 4KB
6.gif 3KB
8.gif 3KB
13.gif 3KB
4.gif 3KB
14.gif 3KB
11.gif 3KB
3.gif 4KB
9.gif 4KB
10.gif 3KB
post.gif 2KB
logo.gif 24KB
reply.gif 2KB
error.jsp 1KB
detail.jsp 3KB
post.jsp 3KB
manage
doTopReg.jsp 581B
doreg.jsp 767B
dologin.jsp 696B
doPost.jsp 2KB
WEB-INF
classes
s2jsp
lg
entity
Reply.class 1KB
User.class 2KB
Topic.class 2KB
Tip.class 3KB
Board.class 1KB
dao
TopicDao.class 330B
ReplyDao.class 330B
impl
UserDaoImpl.class 3KB
TopicDaoImpl.class 5KB
BaseDao.class 2KB
ReplyDaoImpl.class 5KB
BoardDaoImpl.class 3KB
BoardDao.class 187B
UserDao.class 353B
test
test.class 1KB
lib
web.xml 371B
共 75 条
- 1
资源评论
- Niteip2013-10-14帮朋友下的,我并没看过
hackpeng
- 粉丝: 38
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功