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

Java编程

开发平台:

Java

  1. package StudyBbs;
  2. import java.util.*;
  3. import java.sql.Connection;
  4. import java.sql.ResultSet;
  5. public class TopicDisp extends Topic{
  6. private int reCount;
  7. private String lastTalk ;
  8. public TopicDisp(){
  9. }
  10. public int getReCount(){
  11. return reCount;
  12. }
  13. public void setReCount(int reCount) {
  14. this.reCount = reCount;
  15. }
  16. public String getLastTalk(){
  17. return lastTalk;
  18. }
  19. public void setLastTalk(String lastTalk) {
  20. this.lastTalk = lastTalk;
  21. }
  22. public int GetTopicCount(DB db,int sortid) throws Exception{
  23. ResultSet rs,rsNest;
  24.         String strSql=null;
  25.         int iRecordCount=0;
  26.         strSql = "select count(*) from topic where sortid=" + sortid ;
  27. rs = db.OpenSql(strSql);  
  28. if ( rs.next()) {
  29. iRecordCount=rs.getInt(1);
  30. }
  31. return iRecordCount;
  32. }
  33. public Vector search(DB db,int pageid) throws Exception{
  34. Vector Topics = new Vector();
  35. ResultSet rs,rsNest;
  36.         String strSql=null;
  37.         int iRecordCount=0;
  38.         int iCurRecord=0;
  39.         
  40.         strSql = "select * from topic where sortid=" + sortid + " order by time desc";
  41. rs = db.OpenSql(strSql);
  42. int iCount=0;
  43. iCurRecord=pageid * Constants.TOPIC_PAGE_SIZE + 1;          
  44. rs.absolute(iCurRecord);
  45. do{
  46. TopicDisp topic = new TopicDisp();
  47. topic.setId(rs.getInt("id"));
  48. topic.setTitle ( rs.getString("topicname"));
  49. topic.setContent ( rs.getString("topiccontent"));
  50. topic.setOwner ( rs.getString("owner"));
  51. topic.setTime ( rs.getString("time"));
  52. topic.setSortid ( sortid);
  53. topic.setLastTalk (rs.getString("time"));
  54. strSql = "select count(*) from responses where topicid=" + topic.id;
  55. rsNest = db.OpenSql(strSql);
  56. if (rsNest.next()){
  57. topic.setReCount(rsNest.getInt(1));
  58. }
  59.          strSql = "select * from responses where topicid=" + topic.id + " order by time desc" ;
  60. rsNest = db.OpenSql(strSql);
  61. if (rsNest.next()){
  62. topic.setLastTalk (rsNest.getString("time"));
  63. }
  64. Topics.add(topic);
  65. iCount++;
  66. if (iCount>=Constants.TOPIC_PAGE_SIZE){
  67. break;
  68. }
  69. }while(rs.next());
  70. return Topics;
  71. }
  72. }