Topic.java
上传用户:jishiqi_cj
上传日期:2022-08-08
资源大小:24765k
文件大小:2k
源码类别:

Java编程

开发平台:

Java

  1. package StudyBbs;
  2. import java.util.*;
  3. import java.sql.ResultSet;
  4. public class Topic{
  5. protected int id;
  6. protected String title ;
  7. protected String content;
  8. protected String owner;
  9. protected String time;
  10. protected int sortid ;
  11. public Topic(){ }
  12. public void setId(int id) {
  13. this.id = id;
  14. }
  15. public void setTitle(String title) {
  16. this.title = title;
  17. }
  18. public void setContent(String content) {
  19. this.content = content;
  20. }
  21. public void setOwner(String owner) {
  22. this.owner = owner;
  23. }
  24. public void setTime(String time) {
  25. this.time = time;
  26. }
  27. public void setSortid(int sortid) {
  28. this.sortid = sortid;
  29. }
  30. public int getId(){
  31. return id;
  32. }
  33. public String getTitle(){
  34. return title;
  35. }
  36. public String getContent(){
  37. return content;
  38. }
  39. public String getOwner(){
  40. return owner;
  41. }
  42. public String getTime(){
  43. return time;
  44. }
  45. public int getSortid(){
  46. return sortid;
  47. }
  48. public boolean Insert(DB db) throws Exception{
  49.         String strSql;
  50. ResultSet rs;
  51. int iMaxId;
  52.         strSql = "Select max(id) From topic";
  53. rs = db.OpenSql(strSql);  
  54. if ( rs.next()) {
  55. iMaxId=rs.getInt(1)+1;
  56. }
  57. else{
  58. iMaxId=1;
  59. }
  60.         
  61.         strSql = "insert into topic values(" 
  62.          + iMaxId  +",'"
  63. + title  +"','"
  64. + content  +"','"
  65. + owner  +"',sysdate,"
  66. + sortid +")";
  67. if ( db.ExecSql(strSql)==0) {
  68. return false;
  69. }
  70. else{
  71. return true;
  72. }
  73. }
  74. public static Vector Search(DB db,String topicname) throws Exception{
  75. Vector Topics = new Vector();
  76. ResultSet rs,rsNest;
  77.         String strSql=null;
  78.         strSql = "select * from topic where topicname like '%" + topicname + "%'";
  79. rs = db.OpenSql(strSql);
  80. while  (rs.next()){
  81. Topic topic = new Topic();
  82. topic.setId(rs.getInt("id")) ;
  83. topic.setTitle(rs.getString("topicname")) ;
  84. topic.setOwner(rs.getString("owner")) ;
  85. Topics.add(topic);
  86. }
  87. return Topics;
  88. }
  89. public static boolean Delete(DB db,int topicid) throws Exception{
  90.         String strSql;
  91.         strSql = "delete from topic where id='"+topicid+"'";
  92. if ( db.ExecSql(strSql)==0) {
  93. return false;
  94. }
  95. else{
  96. return true;
  97. }
  98. }
  99. }