📄 forumdao.java
字号:
/*******************************************************************\* ** LightningBoard ** ** http://sourceforge.net/projects/lightningboard/ ** ** Copyright (c) 2002 Xiaobo Liu ** *********************************************************************** LICENSE INFORMATION ** ** LightningBoard is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License as ** published by the Free Software Foundation; either version 2 of ** the License, or any later version. ** ** We don't charge anything for the use of LightningBoard, we only ** require you to keep the copyright present on your site and in ** the source files. ** ** LightningBoard is distributed in the hope that it will be useful,** but without any warranty; without even the implied warranty of ** merchantability or fitness for a particular purpose. See the GNU ** General Public License for more details. ** *\*******************************************************************/package liuxiaobo.lb.dao;import java.sql.*;import java.util.*;import liuxiaobo.db.*;import liuxiaobo.lb.*;import liuxiaobo.lb.bean.*;public class ForumDAO { private DBConnectionManager dbcm = DBConnectionManager.getInstance(); public ForumBean execute(int f_id,int start, int range)throws ActionException{ Connection connection=null; try { ForumBean forumBean=new ForumBean(); connection=dbcm.getConnection(); DBAccess dba=new DBAccess(connection); String sql="SELECT f_name,f_u_id,u_name,f_info,f_topics,f_messages FROM forum,user WHERE f_u_id=u_id AND f_id=" + f_id; ResultSet rs=dba.openSelect(sql); //check result if (!rs.next()) return null; rs.beforeFirst(); while (rs.next()){ forumBean.setF_id(String.valueOf(f_id)); forumBean.setF_name(rs.getString("f_name")); forumBean.setF_u_id(rs.getString("f_u_id")); forumBean.setU_name(rs.getString("u_name")); forumBean.setF_info(rs.getString("f_info")); forumBean.setF_topics(rs.getString("f_topics")); forumBean.setF_messages(rs.getString("f_messages")); } rs.close(); dba.closeSelect(); //------------------------ sql="SELECT t_id,t_name,t_u_id,user1.u_name as u_name,t_replies,t_views,t_lasttime,t_u_id2,user2.u_name as u_name2 FROM topic,user user1,user user2 WHERE t_u_id=user1.u_id AND t_u_id2=user2.u_id AND t_f_id=" + f_id + " ORDER BY t_lasttime DESC"; rs = dba.openSelect(sql); rs.last(); int count = rs.getRow(); forumBean.setStart(String.valueOf(start)); forumBean.setRange(String.valueOf(range)); forumBean.setCount(String.valueOf(count)); List topicList=new LinkedList(); if (count>0){ if(start > count){ throw new Exception("NO_TOPICS"); } rs.absolute(start); for(int i=0; i < range && !rs.isAfterLast();i++ ){ Topic topic=new Topic(); topic.setT_id(rs.getString("t_id")); topic.setT_name(rs.getString("t_name")); topic.setT_u_id(rs.getString("t_u_id")); topic.setU_name(rs.getString("u_name")); topic.setT_replies(rs.getString("t_replies")); topic.setT_views(rs.getString("t_views")); topic.setT_lasttime(rs.getString("t_lasttime")); topic.setT_u_id2(rs.getString("t_u_id2")); topic.setU_name2(rs.getString("u_name2")); topicList.add(topic); rs.next(); } } forumBean.setTopics(topicList); rs.close(); dba.closeSelect(); //jump CommonDAO commonDAO=new CommonDAO(); forumBean.setForumMap(commonDAO.getForumMap(dba)); return forumBean; } catch (Exception ex) { throw new ActionException(ex); }finally{ try { dbcm.freeConnection(connection); } catch (SQLException ex) { // } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -