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

📄 topicmanagedaojdbcimple.java

📁 用myeclipse开发的一个BBS论坛系统的源代码。大家可以看看。
💻 JAVA
字号:
package cn.edu.rjxy.dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;

import javax.sql.DataSource;

public class TopicManageDAOJDBCImple implements TopicManageDAOInterface
{
	private java.sql.Connection con=null;
	ConnectDBBean connectDBBean=null;
	public TopicManageDAOJDBCImple() 
	{
		connectDBBean=new ConnectDBBean();
	}
	public boolean  InsertOneTopicInfo(TopicInfoPO  oneTopicInfoPO) 
	{
		String insert_SqlStatement=null;		
		insert_SqlStatement="insert into topic(userid,title,content,posttime,parentid) values(?,?,?,?,?)";
		con=connectDBBean.getConnection();
	    System.out.println(oneTopicInfoPO.getUsername());
		try
		{
			
			java.sql.PreparedStatement pstmt = con.prepareStatement(insert_SqlStatement,
					ResultSet.TYPE_SCROLL_SENSITIVE,
					ResultSet.CONCUR_UPDATABLE);
			pstmt.setString(1, oneTopicInfoPO.getUsername());
			pstmt.setString(2, oneTopicInfoPO.getTitle());
			pstmt.setString(3, oneTopicInfoPO.getContent());
			pstmt.setString(4, oneTopicInfoPO.getPosttime());
			pstmt.setString(5, oneTopicInfoPO.getParentid());
			pstmt.executeUpdate();
		}
		catch(SQLException e)
		{
			e.printStackTrace();
			System.out.println("在插入数据库表时出现错误!");
			return false;
		}
		return true;
	}
	public  Collection getAllTopic() throws Exception {
		con=connectDBBean.getConnection();
		PreparedStatement pStmt = null;
		//Vector v = new Vector();
		Collection ret=new ArrayList();
		ResultSet rs = null;
		try {
			String sql="select * from topic where parentid is null";
			pStmt = con.prepareStatement(sql);
			rs = pStmt.executeQuery();
			
			while (rs.next()) {
//				v.add(new Topic(rs.getString("title"), rs
//						.getString("userid"),rs.getString("content"),rs.getDate("pubTime")));
				TopicInfoPO  top=new TopicInfoPO();
				top.id=rs.getString("id");
				top.setTitle(rs.getString("title"));
				top.setContent(rs.getString("content"));
				top.setUsername(rs.getString("userid"));
				top.setPosttime(rs.getString("posttime"));
				ret.add(top);		
			}
			return ret;
		} catch (SQLException e) {
			throw e;
		} finally {
			try {
				rs.close();
				pStmt.close();
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}



	 
	 
	 public  Collection getAllAnswer(String parentid) throws Exception {
			con=connectDBBean.getConnection();
			PreparedStatement pStmt = null;
			//Vector v = new Vector();
			Collection ret=new ArrayList();
			ResultSet rs = null;
			try {
				String sql="select * from topic where parentid='"+parentid+"'";
				pStmt = con.prepareStatement(sql);
				rs = pStmt.executeQuery();
				
				while (rs.next()) {
//					v.add(new Topic(rs.getString("title"), rs
//							.getString("userid"),rs.getString("content"),rs.getDate("pubTime")));
					TopicInfoPO  top=new TopicInfoPO();
					top.setTitle(rs.getString("title"));
					top.setContent(rs.getString("content"));
					top.setUsername(rs.getString("userid"));
					top.setPosttime(rs.getString("posttime"));
					ret.add(top);		
				}
				return ret;
			} catch (SQLException e) {
				throw e;
			} finally {
				try {
					rs.close();
					pStmt.close();
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
		 public boolean  UpdateOneTopicInfo(TopicInfoPO  oneTopicInfoPO) 
		 {
			return false;
		 }

		 public boolean  AnswerOneTopicInfo(TopicInfoPO  oneTopicInfoPO) 
		 {
			return false;
		 }

	 
	 
}

⌨️ 快捷键说明

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