📄 replymgmt.java
字号:
package yy;
import yy.Reply;
import yy.DataBaseConnection;
import java.io.*;
import java.util.*;
import java.sql.*;
public class ReplyMgmt {
private Connection con;
//构造方法,获得数据库的连接
public ReplyMgmt() {
this.con = DataBaseConnection.getConnection();
}
//删除一条特定的回复
public void deleteOneReply(int replyId) throws Exception {
Statement stmt = con.createStatement();
stmt.execute("delete from Reply where reply_id=" + replyId);
//stmt.close();
}
//删除和一条帖子相关的所有回复
public void deleteReplyBySubjectId(int subjectId) throws Exception {
Statement stmt = con.createStatement();
stmt.execute("delete from Reply where subject_id=" + subjectId);
//stmt.close();
}
//返回和一条帖子相关的所有回复
public Collection getReplyBySubjectId(int subjectId) throws Exception {
Statement stmt = con.createStatement();
ResultSet rst = stmt.executeQuery("select * from Reply where subject_id=" +
subjectId + " order by reply_time");
Collection ret = new ArrayList();
while (rst.next()) {
Reply temp = new Reply();
temp.setReplyId(rst.getInt("reply_id"));
temp.setSubjectId(rst.getInt("subject_id"));
temp.setReplyTitle(rst.getString("reply_title"));
temp.setReplyContent(rst.getString("reply_content"));
java.sql.Date date = rst.getDate("reply_time");
temp.setReplyTime(date);
//temp.setReplyTime(rst.getString("reply_time"));
temp.setReplyAuthor(rst.getString("reply_author"));
temp.setReplyPic(rst.getString("reply_pic"));
temp.setCommunityId(rst.getInt("community_id"));
temp.setReplyTopic(rst.getString("reply_topic"));
ret.add(temp);
}
//rst.close();
//stmt.close();
con.close();
return ret;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -