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

📄 responsedao.java

📁 本人大学时大型作业用JAVA做的一个 BBS系统 模式MVC 非struts版 开发工具JCreator Pro 数据库SQL2
💻 JAVA
字号:
package db;
import java.sql.*;
import java.util.*;
import javax.sql.*;
import javax.naming.*;
import domain.*;
import listener.DataSourceListener;
import actions.*;
public class ResponseDao
{
	private String selectByTopicId="select res_id,res_issureNum,res_topicId,res_content,res_author,res_updatetime from bbsResponses where res_topicId=?";
	private String selectById="select res_id,res_issureNum,res_topicId,res_content,res_author,res_updatetime from bbsResponses where res_id=?";
	private DataSource ds=null;
	public ResponseDao()
	{
		try
		{			
			{
				Context ctx=new InitialContext();
				ds=(DataSource)ctx.lookup(DataSourceListener.JNDI_NAME);
			}	
		}
		catch(Exception e)
		{
		}				
	}	
	public BBSResponse getResponse(int id)
	{
		Connection conn=null;
		BBSResponse response=null;
		try
		{
			conn=ds.getConnection();
			PreparedStatement psmt=conn.prepareStatement(selectById);
			psmt.setInt(1,id);
			ResultSet rs=psmt.executeQuery();
			rs.next();
			response=new BBSResponse(rs.getInt(1),
					rs.getInt(2),
					rs.getInt(3),
					rs.getString(4),
					rs.getString(5),
					rs.getDate(6));
		}
		catch(Exception e)
		{
		}
		finally
		{
			try
			{
				if(conn!=null)
					conn.close();
			}
			catch(Exception ignore)
			{
			}
		}
		return response;
	}
	public void addResponse(String topicId,String content,String userName)
	{
		Connection conn=null;
		BBSResponse response=null;
		try
		{
			conn=ds.getConnection();
			Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
			ResultSet rs=stmt.executeQuery("select * from bbsResponses");
			rs.moveToInsertRow();
			rs.updateInt(3,Integer.parseInt(topicId));
			rs.updateString(4,content);
			rs.updateString(5,userName);
			rs.insertRow();
		}
		catch(Exception e)
		{			
		}
		finally
		{
			try
			{
				if(conn!=null)
					conn.close();
			}
			catch(Exception ignore)
			{
			}
		}		
	}

	public HashMap getResponses(int topicId)
	{
		Connection conn=null;
		HashMap responses=null;
		try
		{
			conn=ds.getConnection();
			PreparedStatement psmt=conn.prepareStatement(selectByTopicId);
			psmt.setInt(1,topicId);
			ResultSet rs=psmt.executeQuery();
			responses=new HashMap();
			while(rs.next())
			{
				BBSResponse response=new BBSResponse();
				response.setId(rs.getInt(1));
				response.setIssureNum(rs.getInt(2));
				response.setTopicId(rs.getInt(3));
				response.setContent(rs.getString(4));
				response.setAuthor(rs.getString(5));
				response.setTime(rs.getDate(6));
				responses.put(response.getId(),response);			
			}
		}
		catch(Exception e)
		{
		}
		finally
		{
			try
			{
				if(conn!=null)
					conn.close();
			}
			catch(Exception ignore)
			{
			}
		}
		return responses;
	}
}

⌨️ 快捷键说明

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