- package StudyBbs;
- import java.util.*;
- import java.sql.ResultSet;
- 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.OpenSql(strSql);
- if ( rs.next()) {
- iMaxId=rs.getInt(1)+1;
- }
- else{
- iMaxId=1;
- }
- strSql = "insert into topic values("
- + iMaxId +",'"
- + title +"','"
- + content +"','"
- + owner +"',sysdate,"
- + sortid +")";
- if ( db.ExecSql(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.OpenSql(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.ExecSql(strSql)==0) {
- return false;
- }
- else{
- return true;
- }
- }
- }