📄 topic.java
字号:
package j2eebbs;
import java.util.*;
import java.sql.ResultSet;
public class Topic {
protected int id;
protected String title;
protected String content;
protected String author;
protected String submittime;
protected int forumid;
public Topic() {
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public int getForumid() {
return forumid;
}
public void setForumid(int forumid) {
this.forumid = forumid;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getSubmittime() {
return submittime;
}
public void setSubmittime(String submittime) {
this.submittime = submittime;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public boolean insert(DB db) throws Exception {
String strSql;
ResultSet rs;
int iMaxId;
strSql = "Select max(id) From topic";
rs = db.OpenSql(strSql);
if (rs.next()) {
iMaxId = rs.getInt(1) + 1;
} else {
iMaxId = 1;
}
GregorianCalendar calendar = new GregorianCalendar();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
String submittime = year + "-" + month + "-" + day;
strSql = "insert into topic values(" + iMaxId + ",'" + title + "','"
+ content + "','" + author + "','" + submittime + "'," + forumid
+ ")";
if (db.ExecSql(strSql) == 0) {
return false;
} else {
return true;
}
}
public static Vector search(DB db, String title) throws Exception {
Vector Topics = new Vector();
ResultSet rs;
String strSql = null;
strSql = "select * from topic where title like '%" + title
+ "%'";
rs = db.OpenSql(strSql);
while (rs.next()) {
Topic topic = new Topic();
topic.setId(rs.getInt("id"));
topic.setTitle(rs.getString("title"));
topic.setAuthor(rs.getString("author"));
Topics.add(topic);
}
return Topics;
}
public static boolean delete(DB db, String id) throws Exception {
String strSql;
strSql = "delete from topic where id=" + id;
if (db.ExecSql(strSql) == 0) {
return false;
} else {
return true;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -