⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 topicdaoimpl.java

📁 实现了简单的JSP论坛 里面还包含几个教学常用例题
💻 JAVA
字号:
/*
 * s2jsp.lg.dao.impl.ReplyDaoImpl.java
 * 2007-7-19
 * ReplyDao的实现类
 */
package s2jsp.lg.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.*;

import s2jsp.lg.dao.TopicDao;
import s2jsp.lg.entity.Topic;

public class TopicDaoImpl extends BaseDao implements TopicDao {
    private Connection        conn  = null;        // 保存数据库连接
    private PreparedStatement pstmt = null;        // 用于执行SQL语句
    private ResultSet         rs    = null ;       // 用户保存查询结果集

    /**
     * 添加主题
     * @param topic
     * @return 增加条数
     */
    public int addTopic(Topic topic) {
        return 0;
    }

    /**
     * 删除主题
     * @param topicId
     * @return 删除条数
     */
    public int deleteTopic(int topicId) {
        return 0;
    }

    /**
     * 更新主题
     * @param topic
     * @return 更新条数
     */
    public int updateTopic(Topic topic) {
        return 0;
    }

    /**
     * 查找一个主题的详细信息
     * @param topicId
     * @return 主题信息
     */
    public Topic findTopic(int topicId) {
        return null; 
    }

    /**
     * 查找主题List
     * @param page
     * @return 主题List
     */
    public List findListTopic(int page, int boardId) {
        List list    = new ArrayList();            // 用来保存主题对象列表
        int rowBegin = 0;                          // 开始行数,表示每页第一条记录在数据库中的行数
        if( page > 1 ) {
            rowBegin = 20 * (page-1);              // 按页数取得开始行数,设每页可以显示10条回复
        }
        String sql = "select top 20 * from TBL_TOPIC where boardId=" + boardId + " and topicId not in(select top "+ rowBegin + " topicId from TBL_TOPIC where boardId=" + boardId + " order by publishTime desc )order by publishTime desc";
        try {
            conn  = this.getConn();                // 获得数据库连接
            pstmt = conn.prepareStatement(sql);    // 得到一个PreparedStatement对象
            rs    = pstmt.executeQuery();          // 执行SQL,得到结果集

            /*  将结果集中的信息取出保存到list中  */
            while ( rs.next() ) {
                Topic topic = new Topic();        // 主题对象
                topic.setTopicId(rs.getInt("topicId"));
                topic.setTitle(rs.getString("title"));
                topic.setPublishTime(rs.getString("publishTime"));
                topic.setUid(rs.getInt("uid"));
                list.add(topic);
            }
        } catch ( Exception e ) {
            e.printStackTrace();                   // 处理异常
        } finally {
            this.closeAll(conn, pstmt, rs);       // 释放资源
        }
        return list;
    }
    
    /**
     * 根据版块id取得该版块的主题数
     * @param boardId
     * @return 主题数
     */
    public int findCountTopic(int boardId) {
        return 0;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -