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

📄 affichebean.java

📁 购物网站
💻 JAVA
字号:
package com;
import java.sql.*;
import java.util.*;
import java.io.*;
/**
 *AfficheBean包含和TABLE_AFFICHE表相关的操作
 */
public class AfficheBean{
	private Connection con;
	//构造方法,获得数据库的连接。
	public AfficheBean(){
		this.con=DataBaseConnection.getConnection();
	}
	/**
	 *搜索所有的信息。
	 *返回由Affiche值对象组成的Collection
	 */
	public Collection getAllAffiche()throws Exception{
		Statement stmt=con.createStatement();
		ResultSet rst=stmt.executeQuery("select * from TABLE_AFFICHE");
		Collection ret=new ArrayList();
		while(rst.next()){
			Affiche temp=new Affiche();
			temp.setAfficheId(rst.getString("AFFICHE_ID"));
			temp.setAfficheNews(rst.getString("AFFICHE_NEWS"));
			temp.setAfficheTime(rst.getString("AFFICHE_SEND_TIME"));

			ret.add(temp);
		}
		con.close();
		return ret;
	}
	
	
	/**
	 *添加一个公告,使用Affiche值对象作为参数传给这个方法。
	 */
	public void addAffiche(Affiche affiche)throws Exception{
		
		PreparedStatement	pstmt=con.prepareStatement("insert into TABLE_AFFICHE values(?,?,?)");
		pstmt.setString(1,affiche.getAfficheId());
		pstmt.setString(2,affiche.getAfficheNews());
		pstmt.setString(3,affiche.getAfficheTime());
		pstmt.execute();
		
	}
	
	/**
	 *按照公告的ID查找,
	 *返回由Affiche值对象组成的Collection
	 */
	public Affiche getAfficheById(String afficheId)throws Exception
	{
		
		Statement stmt=con.createStatement();
		ResultSet rst=stmt.executeQuery("select * from TABLE_AFFICHE where AFFICHE_ID='"+afficheId+"'");
		Affiche affiche=null;
		while(rst.next())
		{
			affiche=new Affiche();
			affiche.setAfficheId(rst.getString("AFFICHE_ID"));
			affiche.setAfficheNews(rst.getString("AFFICHE_NEWS"));
			affiche.setAfficheTime(rst.getString("AFFICHE_SEND_TIME"));
			
		}
		return affiche;
	}
	
	/**
	 *更改信息,使用对象作为参数传给这个方法。
	 */
	public void modifyAffiche(Affiche affiche)throws Exception{
		
		PreparedStatement	pstmt=con.prepareStatement("update TABLE_AFFICHE set AFFICHE_NEWS=?,AFFICHE_SEND_TIME=? where AFFICHE_ID=?");
		pstmt.setString(1,affiche.getAfficheId());
		pstmt.setString(2,affiche.getAfficheNews());
		pstmt.setString(3,affiche.getAfficheTime());
		try{
			pstmt.execute();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
				
	}
	
	/**
	 *删除公告
	 */
	public void deleteAffiche (String afficheId)throws Exception{
		Statement stmt=con.createStatement();
		stmt.execute("delete from TABLE_AFFICHE where AFFICHE_ID='"+afficheId+"'");
	}
	/**
	 *按照时间查找公告,
	 *返回由Affiche值对象组成的Collection
	 */
	public Collection getAfficheByTime(String afficheTime)throws Exception
	{
		Statement stmt=con.createStatement();
		ResultSet rst=stmt.executeQuery("select * from TABLE_AFFICHE where AFFICHE_SEND_TIME='"+afficheTime+"'");
		Collection ret=new ArrayList();
		while(rst.next())
		{
			Affiche temp=new Affiche();
			temp.setAfficheId(rst.getString("AFFICHE_ID"));
			temp.setAfficheNews(rst.getString("AFFICHE_NEWS"));
			temp.setAfficheTime(rst.getString("AFFICHE_SEND_TIME"));
		

			ret.add(temp);
		}
		con.close();
		return ret;
	}
}	

	

⌨️ 快捷键说明

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