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

📄 notice.java

📁 Eclipse+Struts 它可以浏览,编辑,和删除公告.特定等级的用户拥有特定的权限.
💻 JAVA
字号:
package nm;

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

public class Notice {

	int ID;

	String title;

	String content;

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public int getID() {
		return ID;
	}

	public void setID(int id) {
		ID = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public Notice() {
	}

	public Notice(String title, String content) {
		this.title = title;
		this.content = content;
	}

	public Notice(int ID, String title, String content) {
		this.ID = ID;
		this.title = title;
		this.content = content;
	}

	public static Vector search(int pageSize, int page) throws Exception {
		DB db = new DB(DBUtil.connectToDB());
		Vector noticeVector = new Vector();
		ResultSet rs = null;
		String strSql = new String("SELECT * FROM Notice");

		try {
			rs = db.OpenSql(strSql);
			Pageable pgb = new Pageable(rs);
			pgb.setPageSize(pageSize);
			pgb.gotoPage(page);
			rs.absolute(pgb.getRowsCount());

			int i = 0;
			int id = 0;
			String title = null;
			String content = null;
			do {
				id = Integer.parseInt(rs.getString("ID"));

				title = rs.getString("Title");
				content = rs.getString("Content");
				noticeVector.add(new Notice(id, title, content));

				i++;
			} while (rs.next() && i < pgb.getCurrentPageRowsCount());

			return noticeVector;
		} finally {
			try {
				db.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	public Notice searchByID(int ID) throws Exception {
		DB db = new DB(DBUtil.connectToDB());

		ResultSet rs = null;

		try {

			String strSql = "SELECT * FROM notice WHERE ID=" + ID;
			rs = db.OpenSql(strSql);
			Notice bean = null;
			if (rs.next()) {

				bean = new Notice(ID, rs.getString("title"), rs
						.getString("content"));
			}

			return bean;

		} finally {
			try {
				db.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	public void insert() throws Exception {
		DB db = new DB(DBUtil.connectToDB());
		title = new String(title.getBytes("GB2312"), "ISO-8859-1");

		content = new String(content.getBytes("GB2312"), "ISO-8859-1");
		String strSql = "INSERT INTO notice(title, content) values('" + title
				+ "','" + content + "')";
		try {
			db.ExecSql(strSql);
		} catch (Exception ex) {
			System.err.println(ex.getMessage());
			throw ex;
		} finally {
			try {
				System.out.println("finally璇

⌨️ 快捷键说明

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