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

📄 atttoexdbbean.java

📁 北大青鸟在线考试系统,包括在线考试模块,教师管理模块,系统管理模块
💻 JAVA
字号:
/*
 *定义人员、试卷数据操作组件
 */
package TestClass;

import java.sql.*;
import java.util.*;

public class AttToExDBbean
{
	//数据库连接指向空
	private Connection conn=null;
	//根据人员编号列出人员、试卷内容
	private PreparedStatement GetpNoOne=null;
	//引入外部查询语句
	private Statement stmt=null;
	//根据试卷编号列出人员、试卷内容
	private PreparedStatement GetExNoOne=null;
	//列出所有人员、试卷内容
	private PreparedStatement GetAll=null;
	//添加人员、试卷记录
	private PreparedStatement AddStmt=null;
	//修改人员、试卷记录
	private PreparedStatement UpStmt=null;
	private PreparedStatement UpStmt1=null;
	//删除人员、试卷记录
	private PreparedStatement DelStmt=null;	
	
	public AttToExDBbean()
	{
		//声明数据库连接
		String driver,user,pass,dbURL;
		PropertyResourceBundle resourceBundle = (PropertyResourceBundle) PropertyResourceBundle.getBundle("Config");

		driver = resourceBundle.getString("jdbc.driver");
		user = resourceBundle.getString("jdbc.user");
		pass = resourceBundle.getString("jdbc.password");
		dbURL = resourceBundle.getString("jdbc.dbURL");

		try  
		{
			Class.forName(driver);
			conn =DriverManager.getConnection(dbURL,user,pass);
			//根据人员编号列出人员、试卷内容
			GetpNoOne=conn.prepareStatement("Select * From AttToEx Where pNo=?");
			//根据试卷编号列出人员、试卷内容
			GetExNoOne=conn.prepareStatement("Select * From AttToEx Where ExNo=?");
			//引入外部查询语句
			stmt=conn.createStatement();
			//列出所有人员、试卷内容
			GetAll=conn.prepareStatement("Select * From AttToEx");
			//添加人员、试卷记录
			AddStmt=conn.prepareStatement("Insert into AttToEx values(?,?,?)");
			//修改人员、试卷记录
			UpStmt=conn.prepareStatement("Update AttToEx set pScore=? Where pNo=?)");
			UpStmt1=conn.prepareStatement("Update AttToEx set pNo=?,pScore=? Where ExNo=?)");
			//删除人员、试卷记录
			DelStmt=conn.prepareStatement("Delete From AttToEx Where ExNo=? and pNo=?)");
		}
		catch(java.lang.ClassNotFoundException e) 
		{
			System.err.println("AttToExDBbean(): 0" + e.getMessage());
		}
		catch(java.sql.SQLException e)
		{
			System.err.println("AttToExDBbean(): 1" + e.getMessage());
		}
		catch(Exception e)
		{
			System.err.println("AttToExDBbean(): 2" + e.getMessage());	
		}
	}
	
	/*
	 * 数据访问
	 */	
	 
	//列出所有人员、试卷内容
	public ArrayList GetAllData()
	{
		ArrayList rt=new ArrayList();
		
		try 
		{
			ResultSet Rs=GetAll.executeQuery();
			
			AttToExBean beanObj=null;
			while(Rs.next())
			{
				beanObj=new AttToExBean();
				beanObj.setExNo(Rs.getString(1));
				beanObj.setPNo(Rs.getString(2));
				beanObj.setPScore(Rs.getDouble(3));
				rt.add(beanObj);
			}
			Rs.close();
		}
		catch(SQLException ex) 
		{
			System.err.println("AttToExDBbean.GetAllData: " + ex.getMessage());
		}
		return rt;
	}
	
	//根据人员编号列出人员、试卷内容
	public AttToExBean GetpNoOne(String PK_pNo)
	{
		AttToExBean rt=null;
		try 
		{
			GetpNoOne.setString(1,PK_pNo);
			
			ResultSet Rs=GetpNoOne.executeQuery();
			
			if (Rs.next())
			{
				rt=new AttToExBean();
				rt.setExNo(Rs.getString(1));
				rt.setPNo(Rs.getString(2));
				rt.setPScore(Rs.getDouble(3));
			}
			Rs.close();
		}
		catch(SQLException ex) 
		{
			System.err.println("AttToExDBbean.GetOne: " + ex.getMessage());
		}
		return rt;
	}

	//根据试卷编号列出人员、试卷内容
	public AttToExBean GetExNoOne(String PK_ExNo)
	{
		AttToExBean rt=null;
		try 
		{
			GetExNoOne.setString(1,PK_ExNo);
			
			ResultSet Rs=GetExNoOne.executeQuery();
			
			if (Rs.next())
			{
				rt=new AttToExBean();
				rt.setExNo(Rs.getString(1));
				rt.setPNo(Rs.getString(2));
				rt.setPScore(Rs.getDouble(3));
			}
			Rs.close();
		}
		catch(SQLException ex) 
		{
			System.err.println("AttToExDBbean.GetOne: " + ex.getMessage());
		}
		return rt;
	}
	
	//引入外部查询语句
	public boolean executeUpdate(String sql)
	{
		boolean rt=false;
		try
		{
			if(conn!=null)
			{
				stmt.executeUpdate(sql);
			}
		}
		catch(SQLException ex) 
		{
			System.err.println("AttendmentDBbean.ResultSet executeQuery: " + ex.getMessage());
		}
		return rt;
	}
	
	//添加人员、试卷记录
	public boolean InsertDB(AttToExBean obj)
	{
		boolean rt=false;
		try 
		{
			AddStmt.setString(1,obj.getExNo());
			AddStmt.setString(2,obj.getPNo());
			AddStmt.setDouble(3,obj.getPScore());
			
			rt=(AddStmt.executeUpdate()==1);
		}
		catch(SQLException ex) 
		{
			System.err.println("AttToExDBbean.InsertDB: " + ex.getMessage());
		}
		return rt;
	}
		
	//修改人员、试卷记录
	public boolean UpdateDB(AttToExBean obj)
	{
		boolean rt=false;
		try 
		{
			UpStmt.setString(2,obj.getPNo());
			UpStmt.setDouble(1,obj.getPScore());
			
			rt=(UpStmt.executeUpdate()==1);
		}
		catch(SQLException ex) 
		{
			System.err.println("AttToExDBbean.UpdateDB: " + ex.getMessage());
		}	
		
		return rt;
	}
	public boolean UpdateDB1(AttToExBean obj)
	{
		boolean rt=false;
		try 
		{
			UpStmt.setString(3,obj.getExNo());
			UpStmt.setString(1,obj.getPNo());
			UpStmt.setDouble(2,obj.getPScore());
			
			rt=(UpStmt.executeUpdate()==1);
		}
		catch(SQLException ex) 
		{
			System.err.println("AttToExDBbean.UpdateDB: " + ex.getMessage());
		}	
		
		return rt;
	}

	//删除人员、试卷记录
	public boolean DeleteDB(String PK_pNo)
	{
		boolean rt=false;
		try 
		{
			DelStmt.setString(1,PK_pNo);
			rt=(DelStmt.executeUpdate()==1);
		}
		catch(SQLException ex) 
		{
			System.err.println("AttToExDBbean.DeleteDB: " + ex.getMessage());
		}
		
		return rt;		
	}	
	
	//关闭数据	
	public void Close()
	{
		try
		{
			if(conn != null)
			{
				GetAll.close();
				AddStmt.close();
				UpStmt.close();
				UpStmt1.close();
				DelStmt.close();
				GetpNoOne.close();
				GetExNoOne.close();
				conn.close();
				conn=null;
			}
		}
		catch(java.sql.SQLException e)
		{
			System.err.println("DataBaseBean():close " + e.getMessage());
		}
	}
}

⌨️ 快捷键说明

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