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

📄 topicdaoimp.java

📁 学习资料学习资料学习资料学习资料学习资料
💻 JAVA
字号:
package com.java.dao;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import com.java.dao.impl.TopicDao;
import com.java.entity.TopicExtendsTip;

public class TopicDaoimp extends Conn implements TopicDao {
	private Connection conn=null;
	private PreparedStatement pstmt=null;
	private ResultSet rs=null;
	
	public int AddTopic(TopicExtendsTip topicExtendsTip) {
		String sql="insert into jspTopic values(?,?,?,?,?,?)";
		String [] topic=new String[6];
		topic[0]=topicExtendsTip.getTitle();
		topic[1]=topicExtendsTip.getContent();
		topic[2]=topicExtendsTip.getPublishTime();
		topic[3]=topicExtendsTip.getModifyTime();
		topic[4]=String.valueOf(topicExtendsTip.getUid());
		topic[5]=String.valueOf(topicExtendsTip.getBoardid());
		return executeSql(sql,topic);
		
	}

	public int DeletTopic(int topicid) {
		String sql="delete from jspTopic where topicid=?";
		String [] topic=new String[1];
		topic[0]=String.valueOf(topicid);
		return executeSql(sql,topic);
	}

	public List<TopicExtendsTip> FindListTopic(int page, int boardId) {
		List<TopicExtendsTip> list =new ArrayList();
		int rowBegin=0;
		if(page>1){
			rowBegin=20*(page-1);
		}
		String sql="select top 20 * from topic where boardid="+boardId+"and topicid not in(select top "+rowBegin+"topicid from topic where boardid="+boardId+"order by publishtime desc)order by publishtime desc";
		try {
			conn = sqlconnection();
			pstmt = conn.prepareStatement(sql);
			rs = pstmt.executeQuery();
			while (rs.next()) {
				TopicExtendsTip topicExtendsTip = new TopicExtendsTip();
				topicExtendsTip.setTopicid(rs.getInt("topicid"));
				topicExtendsTip.setTitle(rs.getString("topictitle"));
				topicExtendsTip.setContent(rs.getString("topiccontent"));
				topicExtendsTip.setPublishTime(rs.getString("publishtime"));
				topicExtendsTip.setModifyTime(rs.getString("modifytime"));
				topicExtendsTip.setUid(rs.getInt("uid"));
				topicExtendsTip.setBoardid(rs.getInt("boardid"));
				list.add(topicExtendsTip);
			}
		} catch (Exception e) {
			System.out.println("查询主题列表异常");
		}finally{
			closeConnection(conn, pstmt, rs);
		}		
		return list;
	}

	public TopicExtendsTip FindTopic(int topicid) {
		String sqlquery="select * from jspTopic where topicid=?";
		TopicExtendsTip topicExtendsTip=new TopicExtendsTip();
		try {
			pstmt=sqlconnection().prepareStatement(sqlquery);
			pstmt.setInt(1, topicid);
			rs=pstmt.executeQuery();
			if(rs.next()){
				topicExtendsTip.setTopicid(rs.getInt("topicid"));
				topicExtendsTip.setTitle(rs.getString("topictitle"));
				topicExtendsTip.setContent(rs.getString("topiccontent"));
				topicExtendsTip.setPublishTime(rs.getString("publishtime"));
				topicExtendsTip.setModifyTime(rs.getString("modifytime"));
				topicExtendsTip.setUid(rs.getInt("uid"));
				topicExtendsTip.setBoardid(rs.getInt("boardid"));
			}
		} catch (SQLException e) {
			System.out.println("根据ID查询异常");
			e.printStackTrace();
		}
		finally{
			closeConnection(conn, pstmt, rs);
		}
		return topicExtendsTip;
	}

	public int UpdateTopic(TopicExtendsTip topicExtendsTip) {
		String sql="update jspTopic set topictitle=?,topiccontent=?,modifytime=?,boardid=?";
		String [] topic=new String[4];
		topic[0]=topicExtendsTip.getTitle();
		topic[1]=topicExtendsTip.getContent();
		topic[2]=topicExtendsTip.getModifyTime();
		topic[3]=String.valueOf(topicExtendsTip.getBoardid());
		return executeSql(sql,topic);
	}
}

⌨️ 快捷键说明

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