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

📄 topic.java

📁 该系统利用Java实现简单论坛功能
💻 JAVA
字号:
package ch11.bean;

import java.util.*;
import java.sql.ResultSet;
import ch11.util.*;

public class Topic{
	
	protected int id;
	protected String title ;
	protected String content;
	protected String owner;
	protected String time;
	protected int sortid ;
	
	public Topic(){	}
	
	public void setId(int id) {
		this.id = id;
	}
	
	public void setTitle(String title) {
		this.title = title;
	}
	
	public void setContent(String content) {
		this.content = content;	
	}
	
	public void setOwner(String owner) {
		this.owner = owner;
	}
	
	public void setTime(String time) {
		this.time = time;
	}
	
	public void setSortid(int sortid) {
		this.sortid = sortid;	
	}
		
	public int getId(){
		
		return id;
		
	}	
	
	public String getTitle(){
		
		return title;
		
	}
		
	public String getContent(){
		
		return content;
		
	}	
		
	public String getOwner(){
		
		return owner;
		
	}	
		
	public String getTime(){
		
		return time;
		
	}	
	
	public int getSortid(){
		
		return sortid;
		
	}
	
	public boolean Insert(DB db) throws Exception{
        String strSql;
		ResultSet rs;
		int iMaxId;
        strSql = "Select max(id) From topic";
		rs = db.execQuery(strSql);  
		if ( rs.next()) {
			iMaxId=rs.getInt(1)+1;
		}
		else{
			iMaxId=1;
		}
        
        strSql = "insert into topic values(" 
        		+ iMaxId 	+",'"
				+ title 	+"','"
				+ content 	+"','"
				+ owner 	+"',now(),"
				+ sortid	+")";
		if ( db.execUpdate(strSql)==0) {
			return false;
		}
		else{
			return true;
		}
	
	}
	
	public static Vector Search(DB db,String topicname) throws Exception{
		Vector Topics = new Vector();
		ResultSet rs,rsNest;
        String strSql=null;
		
        strSql = "select * from topic where topicname like '%" + topicname + "%'";
		rs = db.execQuery(strSql);
		
		while  (rs.next()){
			Topic topic = new Topic();
			
			topic.setId(rs.getInt("id")) ;
			topic.setTitle(rs.getString("topicname")) ;
			topic.setOwner(rs.getString("owner")) ;
			
			Topics.add(topic);
		}
					
		return Topics;
	}
	
	public static boolean Delete(DB db,int topicid) throws Exception{
        String strSql;
        strSql = "delete from topic where id='"+topicid+"'";
		if ( db.execUpdate(strSql)==0) {
			return false;
		}
		else{
			return true;
		}
	}	
		
}

⌨️ 快捷键说明

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