ForumBookMark.java
上传用户:yuyunping
上传日期:2013-03-21
资源大小:1844k
文件大小:3k
源码类别:

Java书籍

开发平台:

Java

  1. package net.acai.forum;
  2. /**
  3.  * Title:        清清网络
  4.  * Description:
  5.  * Copyright:    Copyright (c) 2002
  6.  * Company:      www.qingqing.com
  7.  * @author:       qingqing
  8.  * @version 1.0
  9.  */
  10. import net.acai.forum.*;
  11. import net.acai.database.*;
  12. import javax.servlet.http.*;
  13. import java.sql.*;
  14. import net.acai.util.*;
  15. import java.util.Vector;
  16. import net.acai.database.*;
  17. public class ForumBookMark
  18. {
  19. public ForumBookMark(){
  20. }
  21. public  static void addFav(HttpServletRequest request) throws Exception{
  22. int forumID;
  23. try{
  24. forumID=ParamUtil.getInt(request,"forumID");
  25. }
  26. catch(Exception e){
  27. throw new Exception("请指定论坛版面。");
  28. }
  29. int announceID;
  30. try{
  31. announceID=ParamUtil.getInt(request,"announceID");
  32. }
  33. catch(Exception e){
  34. throw new Exception("请指定相关贴子或者是非法的贴子参数。");
  35. }
  36. int rootID;
  37. try{
  38. rootID=ParamUtil.getInt(request,"rootID");
  39. }
  40. catch(Exception e){
  41. throw new Exception("请指定相关贴子或者是非法的贴子参数。");
  42. }
  43. ////////////////////////////////////
  44. String url="dispbbs.jsp?forumID="+forumID+"&rootID="+rootID+"&announceID="+announceID;
  45. DBConnect dbc=new DBConnect();
  46. String sql="select topic,rootid,announceid,boardid from bbs.bbs1 where announceid="+announceID+" and rootid="+rootID+" and boardid="+forumID;
  47. ResultSet rs=dbc.executeQuery(sql);
  48. if(!rs.next()){
  49. dbc.close();
  50. throw new Exception("没有相关贴子。");
  51. }
  52. //rs.next();
  53. String topic=rs.getString(1);
  54. rs.close();
  55. String userName=GCookie.getCookieValue(request,"UJBBUName","");
  56. sql="insert into bbs.bookmark(username,topic,url,addtime) values(?,?,'"+url+"',getdate())";
  57. dbc.prepareStatement(sql);
  58. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  59. dbc.setBytes(2,(new String(topic.getBytes("ISO-8859-1"),"GBK")).getBytes());
  60. dbc.executeUpdate();
  61. dbc.close();
  62. }
  63. public static Vector getBookMarkList(HttpServletRequest request) throws Exception{
  64. String userName=GCookie.getCookieValue(request,"UJBBUName","");
  65. String sql="select * from bbs.bookmark where username=? order by id desc";
  66. DBConnect dbc=new DBConnect();
  67. dbc.prepareStatement(sql);
  68. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  69. ResultSet rs=dbc.executeQuery();
  70. Vector bookMarkList=new Vector();
  71. while(rs.next()){
  72. BookMark bookMark=new BookMark();
  73. bookMark.setID(rs.getInt(1));
  74. bookMark.setUserName(rs.getString(2));
  75. bookMark.setURL(rs.getString(3));
  76. bookMark.setTopic(rs.getString(4));
  77. bookMark.setAddTime(rs.getString(5));
  78. bookMarkList.add(bookMark);
  79. }
  80. dbc.close();
  81. return bookMarkList;
  82. }
  83. public static void delBookMark(HttpServletRequest request) throws Exception{
  84. int ID;
  85. String userName=GCookie.getCookieValue(request,"UJBBUName","");
  86. try{
  87. ID=ParamUtil.getInt(request,"id");
  88. }
  89. catch(Exception e){
  90. throw new Exception("请指定相应的参数!");
  91. }
  92. String  sql="delete from bbs.bookmark where username=? and id="+ID;
  93. DBConnect dbc=new DBConnect(sql);
  94. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  95. dbc.executeUpdate();
  96. dbc.close();
  97. }
  98. }