topicbean.java

来自「电子书店管理系统」· Java 代码 · 共 94 行

JAVA
94
字号
package com.jspdev.business;

import java.util.*;
import com.jspdev.util.*;
import java.sql.*;
import com.jspdev.vo.*;

/**
 *主要用于执行和topic相关的数据库业务逻辑
 */
public class TopicBean extends BaseBean
{
	public TopicBean()throws Exception
	{
		super();
	}
	
	/**
	 *获得指定topicId的topic的信息
	 */
	public TopicVO getTopic(String topicId)throws Exception
	{
		if(con.isClosed()) con=DatabaseConn.getConnection();
		Statement stmt=con.createStatement();
		ResultSet rst=stmt.executeQuery("select * from Topic where id='"+topicId+"'");
		TopicVO top=new TopicVO();
		if(rst.next())
		{
			top.setId(rst.getString("id"));
			top.setTitle(rst.getString("title"));
			top.setContent(rst.getString("content"));
			top.setEmail(rst.getString("email"));
			top.setAuthor(rst.getString("author"));
			top.setPubTime(rst.getDate("pubtime"));
		}
		rst.close();
		con.close();

		return top;
	}
	
	/**
	 *获得指定topicId的reply的信息
	 */
	public TopicVO getReply(String replyId)throws Exception
	{
		if(con.isClosed()) con=DatabaseConn.getConnection();
		Statement stmt=con.createStatement();
		ResultSet rst=stmt.executeQuery("select * from reply where id='"+replyId+"'");
		TopicVO top=new TopicVO();
		if(rst.next())
		{
			top.setId(rst.getString("id"));
			top.setTopicId(rst.getString("topicId"));
			top.setTitle(rst.getString("title"));
			top.setContent(rst.getString("content"));
			top.setEmail(rst.getString("email"));
			top.setAuthor(rst.getString("author"));
			top.setPubTime(rst.getDate("pubtime"));
		}
		rst.close();
		con.close();
		return top;
	}
	
	/**
	 *获得指定topicid的topic的所有回复的信息
	 */
	public Collection getReplys(String topicId)throws Exception
	{
		if(con.isClosed()) con=DatabaseConn.getConnection();
		Statement stmt=con.createStatement();
		ResultSet rst=stmt.executeQuery("select * from reply where topicId='"+topicId+"'");
		Collection ret=new ArrayList();
		while(rst.next())
		{
			TopicVO top=new TopicVO();
			top.setId(rst.getString("id"));
			top.setTopicId(rst.getString("topicId"));
			top.setTitle(rst.getString("title"));
			top.setContent(rst.getString("content"));
			top.setEmail(rst.getString("email"));
			top.setAuthor(rst.getString("author"));
			top.setPubTime(rst.getDate("pubtime"));
			ret.add(top);
		}
		rst.close();
		stmt.close();
		con.close();

		return ret;
	}
		
}

⌨️ 快捷键说明

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