package dao;
import entity.Topic;
import utils.DBUtils;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class TopicDao {
public static Integer add(Topic t)throws SQLException{
PreparedStatement prep;
String sql="INSERT INTO topic(`ptext`,`pauthor`,`ptime`) VALUE(?,?,?)";
Connection connection= DBUtils.getConnection();
prep=connection.prepareStatement(sql);
prep.setString(1,t.getpText());
prep.setString(2,t.getpAuthor());
prep.setTimestamp(3, (Timestamp) t.getpTime());
prep.executeUpdate();
DBUtils.release(prep);
prep=connection.prepareStatement("SELECT MAX(pid) as p from topic");
ResultSet rs=prep.executeQuery();
if(rs.next()){
return rs.getInt("p");
}
return null;
}
public static List<Topic> getByPid(int id) throws SQLException{
Connection connection=DBUtils.getConnection();
PreparedStatement preparedStatement;
String sql="SELECT * FROM topic WHERE pid=?";
List<Topic> topics=new ArrayList<Topic>();
preparedStatement=connection.prepareStatement(sql);
preparedStatement.setInt(1,id);
ResultSet rs=preparedStatement.executeQuery();
if(rs.next()){
Topic topic=new Topic();
topic.setPid(rs.getInt("pid"));
topic.setpText(rs.getString("ptext"));
topic.setpAuthor((rs.getString("pauthor")));
topic.setpTime(rs.getTimestamp("ptime"));
topic.setpCount(rs.getInt("pcount"));
topics.add(topic);
}
return topics;
}
//查看全部topic
public static List<Topic> getAllTopic() throws SQLException{
Connection connection=DBUtils.getConnection();
PreparedStatement preparedStatement;
String sql="SELECT topic.pid,topic.ptext,topic.pauthor,topic.ptext,cnt.pcount,topic.ptime FROM topic LEFT JOIN (SELECT pid,count(1) as pcount FROM Invitation GROUP BY pid) cnt on cnt.pid=topic.pid ORDER BY topic.pid DESC ";
List<Topic> topics=new ArrayList<Topic>();
preparedStatement=connection.prepareStatement(sql);
ResultSet rs=preparedStatement.executeQuery();
while(rs.next()){
Topic topic=new Topic();
topic.setPid(rs.getInt("pid"));
topic.setpText(rs.getString("ptext"));
topic.setpAuthor((rs.getString("pauthor")));
topic.setpTime(rs.getTimestamp("ptime"));
topic.setpCount(rs.getInt("pcount"));
topics.add(topic);
}
return topics;
}
//更新pcount
/*
public static void updateCount(int pid,int count) throws SQLException{
Connection connection=DBUtils.getConnection();
PreparedStatement preparedStatement;
String sql="UPDATE topic set pcount=? WHERE pid=?";
preparedStatement=connection.prepareStatement(sql);
preparedStatement.setInt(1,count);
preparedStatement.setInt(2,pid);
preparedStatement.executeUpdate();
DBUtils.release(preparedStatement);
}*/
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于JavaEE+bootstrap完成的小型博客论坛网站,可以实现添加帖子,查看帖子,删除帖子等功能.zip
共52个文件
java:18个
jsp:10个
xml:8个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 175 浏览量
2022-06-26
13:20:02
上传
评论
收藏 1.33MB ZIP 举报
温馨提示
基于JavaEE+bootstrap完成的小型博客论坛网站,可以实现添加帖子,查看帖子,删除帖子等功能.zip 大学生课程设计 基于javaee的课程设计 自己大二写的课程设计
资源推荐
资源详情
资源评论
收起资源包目录
基于JavaEE+bootstrap完成的小型博客论坛网站,可以实现添加帖子,查看帖子,删除帖子等功能.zip (52个子文件)
website-master
src
utils
MailUtils.java 2KB
DBUtils.java 2KB
SecureUtils.java 3KB
dao
UserDao.java 2KB
InvitationDao.java 3KB
TopicDao.java 4KB
servlet
DeleteServlet.java 1KB
Reset.java 2KB
LoginServlet.java 3KB
ForumServlet.java 1KB
Change.java 2KB
pwInvitation.java 3KB
ForgetServlet.java 3KB
PersonServlet.java 2KB
publishTopic.java 2KB
entity
User.java 1KB
Invitation.java 2KB
Topic.java 2KB
web
login.jsp 3KB
WEB-INF
web.xml 304B
index.jsp 355B
forget.jsp 2KB
register.jsp 4KB
change.jsp 3KB
WatchInvitation.jsp 4KB
fatopic.jsp 2KB
header.jsp 2KB
forum.jsp 3KB
assets
summernote
summernote.js 294KB
summernote.css 18KB
font
summernote.ttf 17KB
summernote.eot 17KB
summernote.woff 10KB
summernote.js.map 470KB
summernote.min.js 125KB
lang
summernote-zh-CN.min.js 3KB
summernote-zh-CN.js 4KB
imge
write.png 7KB
person.jsp 3KB
.idea
uiDesigner.xml 9KB
libraries
mysql_connector_java_8_0_18.xml 488B
dataSources
d6799808-5a34-4269-93bf-a700166a4bd8.xml 4KB
misc.xml 273B
modules.xml 254B
artifacts
website_war_exploded.xml 717B
dataSources.xml 878B
lib
mail-1.4.7.jar 509KB
gson-2.8.5.jar 236KB
jstl.jar 20KB
activation-1.1.jar 62KB
standard.jar 384KB
website.iml 1KB
共 52 条
- 1
资源评论
我慢慢地也过来了
- 粉丝: 5859
- 资源: 3759
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功