⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 forum.java

📁 BBS论坛管理系统
💻 JAVA
字号:
package j2eebbs;

import java.sql.ResultSet;
import java.util.Vector;

public class Forum {

	private int id;

	private String forumname;

	private String manager;

	private int topicNum;

	private int lastTopicId;

	private String lastTopicTitle = "";

	private String lastTopicAuthor = "";

	private String lastTopicTime = "";

	public String getForumname() {
		return forumname;
	}

	public void setForumname(String forumname) {
		this.forumname = forumname;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getLastTopicAuthor() {
		return lastTopicAuthor;
	}

	public void setLastTopicAuthor(String lastTopicAuthor) {
		this.lastTopicAuthor = lastTopicAuthor;
	}

	public int getLastTopicId() {
		return lastTopicId;
	}

	public void setLastTopicId(int lastTopicId) {
		this.lastTopicId = lastTopicId;
	}

	public String getLastTopicTime() {
		return lastTopicTime;
	}

	public void setLastTopicTime(String lastTopicTime) {
		this.lastTopicTime = lastTopicTime;
	}

	public String getLastTopicTitle() {
		return lastTopicTitle;
	}

	public void setLastTopicTitle(String lastTopicTitle) {
		this.lastTopicTitle = lastTopicTitle;
	}

	public String getManager() {
		return manager;
	}

	public void setManager(String manager) {
		this.manager = manager;
	}

	public int getTopicNum() {
		return topicNum;
	}

	public void setTopicNum(int topicNum) {
		this.topicNum = topicNum;
	}

	public Forum(int id, String forumname, String manager, int topicNum,
			int lastTopicId, String lastTopicTitle, String lastTopicAuthor,
			String lastTopicTime) {
		this.id = id;
		this.forumname = forumname;
		this.manager = manager;
		this.topicNum = topicNum;
		this.lastTopicId = lastTopicId;
		this.lastTopicTitle = lastTopicTitle;
		this.lastTopicAuthor = lastTopicAuthor;
		this.lastTopicTime = lastTopicTime;

	}

	public Forum(int id, String forumname, String manager) {
		this.id = id;
		this.forumname = forumname;
		this.manager = manager;
	}
	
	public static Vector search(DB db) throws Exception {
		int topicNum = 0;
		int lastTopicId;
		String lastTopicTitle;
		String lastTopicAuthor;
		String lastTopicTime;

		Vector forumVector = new Vector();
		ResultSet rs, rsTopic;
		String strSql;
		int forumid;

		strSql = "select * from forum";
		rs = db.OpenSql(strSql);

		while (rs.next()) {
			lastTopicId = 0;
			lastTopicTitle = null;
			lastTopicAuthor = null;
			lastTopicTime = null;

			forumid = rs.getInt("id");
			strSql = "select count(*) from topic where forumid=" + forumid;
			rsTopic = db.OpenSql(strSql);
			if (rsTopic.next()) {
				topicNum = rsTopic.getInt(1);
			}

			strSql = "select * from topic where forumid=" + forumid
					+ " order by forumid desc";
			rsTopic = db.OpenSql(strSql);
			if (rsTopic.next()) {
				lastTopicId = rsTopic.getInt("id");
				lastTopicTitle = rsTopic.getString("title");
				lastTopicTime = rsTopic.getString("submittime");
				lastTopicAuthor = rsTopic.getString("author");
			}

			forumVector.add(new Forum(forumid, rs.getString("forumname"), rs
					.getString("manager"), topicNum, lastTopicId,
					lastTopicTitle, lastTopicTime, lastTopicAuthor));

		}
		return forumVector;
	}

	public static Vector searchAllForums(DB db) throws Exception {
		int forumid = 0;
		String forumname = null;
		String manager = null;

		Vector forumVector = new Vector();
		ResultSet rs;
		String strSql;

		strSql = "select * from forum";
		rs = db.OpenSql(strSql);

		while (rs.next()) {
			forumid = rs.getInt("id");
			forumname = rs.getString("forumname");
			manager = rs.getString("manager");

			forumVector.add(new Forum(forumid, forumname, manager));

		}
		return forumVector;
	}
	public static boolean insert(DB db, String forumname) throws Exception {
		String strSql;
		ResultSet rs;
		int iMaxId;
		strSql = "select max(id) from forum";
		rs = db.OpenSql(strSql);
		if (rs.next()) {
			iMaxId = rs.getInt(1) + 1;
		} else {
			iMaxId = 1;
		}

		strSql = "insert into forum values('" + iMaxId + "','" + forumname
				+ "','')";
		if (db.ExecSql(strSql) == 0) {
			return false;
		} else {
			return true;
		}
	}

	public static boolean delete(DB db, String forumid) throws Exception {
		String strSql;
		strSql = "delete from forum where id=" + forumid;
		if (db.ExecSql(strSql) == 0) {
			return false;
		} else {
			return true;
		}
	}

	public static boolean edit(DB db, String forumid, String forumname,
			String manager) throws Exception {
		String strSql;
		strSql = "update forum set forumname='" + forumname + "',manager='"
				+ manager + "'where id=" + forumid;
		if (db.ExecSql(strSql) == 0) {
			return false;
		} else {
			return true;
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -