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

📄 classtest.java

📁 基于java的jsp开发的在线考试系统 基于java的jsp开发的在线考试系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				throw new SQLException("申请失败:试卷库中的试卷都已考过,请联系管理员增加试卷!");
			}
			else if(returnValue==-3)
			{
				throw new SQLException("申请失败:你已经申请了此科目的试卷或该班正在考此类试卷,如要重新申请试卷,请作废原申请的试卷后再申请!");
			}
			else if(returnValue==0){
				throw new SQLException("申请失败:试卷抽取错误!");
			} 
			else{
				return returnValue;	
			}
		}
		catch(SQLException sqlex)
		{
			System.out.println("Insert ClassTest Error:"+sqlex.getMessage());
			throw new SQLException(sqlex.getMessage());
		}
		finally
		{
			try{con.close();ps.close();}
			catch(SQLException sqlex){System.out.println("Insert Close ClassTest Error:"+sqlex.getMessage());}
		}
	}
	
	public int handInsert()throws SQLException
	{
		//sql="insert into ClassTest (ClassID,TestIndexID,TestRequestDate) values(?,?,getDate())";
		Connection con;
		CallableStatement ps=null;
		
		try{con=db.connectToDB();}
		catch(Exception ex){throw new SQLException("Connect database failed!");}
		boolean bTemp;
		try
		{
			ps=con.prepareCall("{?=call pr_HandCreateClassTest(?,?,?)}");
			ps.registerOutParameter(1,java.sql.Types.INTEGER);
			ps.setInt(2,ClassID);
			ps.setInt(3,TestIndexID);
			ps.setInt(4,TeacherID);
			ps.executeUpdate();
			int returnValue=ps.getInt(1);
			if(returnValue==-1)
			{
				throw new SQLException("申请失败:你已经申请了此类试卷!或该班正在参加该类试卷的考试!");
			} 
			else{
				return returnValue;	
			}
		}
		catch(SQLException sqlex)
		{
			System.out.println("Insert ClassTest Error:"+sqlex.getMessage());
			throw new SQLException(sqlex.getMessage());
		}
		finally
		{
			try{con.close();ps.close();}
			catch(SQLException sqlex){System.out.println("Insert Close ClassTest Error:"+sqlex.getMessage());}
		}
	}
	
	public void update()throws SQLException,Exception
	{
		sql="update ClassTest set ClassID=?,TestIndexID=?,TestRequestDate=? where ID=?";
		Connection con;
		PreparedStatement ps=null;
		try{con=db.connectToDB();}
		catch(Exception ex){throw new SQLException("Connect database failed!");}
		try
		{
			ps=con.prepareStatement(sql);
			ps.setInt(1,ClassID);
			ps.setInt(2,TestIndexID);
			ps.setString(3,TestRequestDate);
			int rowCount=ps.executeUpdate();
			if(rowCount==0)
			{
				throw new SQLException("Update ClassTest failed!");
			}
		}
		catch(SQLException sqlex)
		{
			System.err.println("Update ClassTest Error:"+sqlex.getMessage());
			throw new SQLException("Update ClassTest Error");
		}
		catch(Exception e)
		{
			System.out.println("Other Of Update ClassTest Error:"+e.getMessage());
			throw new Exception("Other Of Update ClassTest Error");
		}
		finally
		{
			try{con.close();ps.close();}
			catch(SQLException sqlex){System.out.println("Update Close ClassTest Error:"+sqlex.getMessage());}
		}
	}

	public void activate()throws SQLException
	{
		//激活试卷
		Connection con;
		CallableStatement ps=null;
		
		try{con=db.connectToDB();}
		catch(Exception ex){throw new SQLException("Connect database failed!");}
		boolean bTemp;
		try
		{
			ps=con.prepareCall("{?=call pr_ActivateTest(?,?)}");
			ps.registerOutParameter(1,java.sql.Types.INTEGER);
			ps.setInt(2,ID);
			ps.setInt(3,ClassID);
			ps.executeUpdate();
			int returnValue=ps.getInt(1);
			if(returnValue==1)
			{
				throw new SQLException("激活失败:你该班已经激活一份试卷,请撤销前一份再激活!");
			}
		}
		catch(SQLException sqlex)
		{
			System.out.println("Insert ClassTest Error:"+sqlex.getMessage());
			throw new SQLException(sqlex.getMessage());
		}
		finally
		{
			try{con.close();ps.close();}
			catch(SQLException sqlex){System.out.println("Insert Close ClassTest Error:"+sqlex.getMessage());}
		}
	}

	public void activateCancel()throws SQLException,Exception
	{
		Connection con;
		CallableStatement ps=null;
		try{con=db.connectToDB();}
		catch(Exception ex){throw new SQLException("Connect database failed!");}
		try
		{
			ps=con.prepareCall("{?=call pr_UnActivateTest(?)}");
			ps.registerOutParameter(1,java.sql.Types.INTEGER);
			ps.setInt(2,ID);
			System.out.println(ID);
			ps.executeUpdate();
			int returnValue=ps.getInt(1);
			if(returnValue!=0)
			{
				throw new SQLException("撤销激活操作失败!");
			}
		}
		catch(SQLException sqlex)
		{
			System.err.println("Update ClassTest Error:"+sqlex.getMessage());
			throw new SQLException(sqlex.getMessage());
		}
		catch(Exception e)
		{
			System.out.println("Other Of Update ClassTest Error:"+e.getMessage());
			throw new Exception("Other Of Update ClassTest Error");
		}
		finally
		{
			try{con.close();ps.close();}
			catch(SQLException sqlex){System.out.println("Update Close ClassTest Error:"+sqlex.getMessage());}
		}
	}
	public void testComplete()throws SQLException,Exception
	{
		//设置State字段为0 以表示试卷撤销激活回到试卷申请状态
		sql="update ClassTest set State='1' where ID=?";
		Connection con;
		PreparedStatement ps=null;
		try{con=db.connectToDB();}
		catch(Exception ex){throw new SQLException("Connect database failed!");}
		try
		{
			ps=con.prepareStatement(sql);
			ps.setInt(1,ID);
			int rowCount=ps.executeUpdate();
			if(rowCount==0)
			{
				throw new SQLException("考试完成操作失败!");
			}
		}
		catch(SQLException sqlex)
		{
			System.err.println("Update ClassTest Error:"+sqlex.getMessage());
			throw new SQLException("Update ClassTest Error");
		}
		catch(Exception e)
		{
			System.out.println("Other Of Update ClassTest Error:"+e.getMessage());
			throw new Exception("Other Of Update ClassTest Error");
		}
		finally
		{
			try{con.close();ps.close();}
			catch(SQLException sqlex){System.out.println("Update Close ClassTest Error:"+sqlex.getMessage());}
		}
	}

	public void delete()throws SQLException//试卷作废
	{
		sql="update ClassTest set Del='1' where ID=?";
		Connection con;
		PreparedStatement ps=null;
		try{con=db.connectToDB();}
		catch(Exception ex){throw new SQLException("Connect database failed!");}
		try
		{
			ps=con.prepareStatement(sql);
			ps.setInt(1,ID);
			int rowCount=ps.executeUpdate();
			if(rowCount==0)
			{
				throw new SQLException("Delete ClassTest failed!");
			}
		}
		catch(SQLException sqlex)
		{
			System.out.println("Delete ClassTest Error:"+sqlex.getMessage());
			throw new SQLException("Delete ClassTest Error");
		}
		finally
		{
			try{con.close();ps.close();}
			catch(SQLException sqlex){System.out.println("Delete Close ClassTest Error:"+sqlex.getMessage());}
		}
	}
	
	public void realDelete()throws SQLException
	{
		sql="delete ClassTest where ID=?";
		Connection con;
		PreparedStatement ps=null;
		try{con=db.connectToDB();}
		catch(Exception ex){throw new SQLException("Connect database failed!");}
		try
		{
			ps=con.prepareStatement(sql);
			ps.setInt(1,ID);
			int rowCount=ps.executeUpdate();
			if(rowCount==0)
			{
				throw new SQLException("realDelete ClassTest failed!");
			}
		}
		catch(SQLException sqlex)
		{
			System.out.println("realDelete ClassTest Error:"+sqlex.getMessage());
			throw new SQLException("realDelete ClassTest Error");
		}
		finally
		{
			try{con.close();ps.close();}
			catch(SQLException sqlex){System.out.println("realDelete Close ClassTest Error:"+sqlex.getMessage());}
		}
	}
	
	public void restor()throws SQLException//取消作废
	{
		sql="select count(id) from View_ClassTest where Del='0' and State='0' and ClassID=? and Project_CN=? ";
		System.out.println(this.Project_CN+","+this.ClassID);
		Connection con;
		PreparedStatement ps=null;
		try{con=db.connectToDB();}
		catch(Exception ex){throw new SQLException("Connect database failed!");}
		try
		{
			ps=con.prepareStatement(sql);
			ps.setInt(1,this.ClassID);
			ps.setString(2,this.Project_CN.trim());
			
			ResultSet rs=ps.executeQuery();
			rs.next();
			int rowCount=rs.getInt(1);
			System.out.println(rowCount);
			if(rowCount!=0)
			{
				throw new SQLException("该班已申请了该科目的试卷,请作废申请的试卷再进行恢复操作");
			}
		}
		catch(SQLException sqlex)
		{
			System.out.println("Restor ClassTest Error:"+sqlex.getMessage());
			throw new SQLException(sqlex.getMessage());
		}
		finally
		{
			try{con.close();ps.close();}
			catch(SQLException sqlex){System.out.println("Restor Close ClassTest Error:"+sqlex.getMessage());}
		}
		
		sql="update ClassTest set Del='0' where ID=?";
		try{con=db.connectToDB();}
		catch(Exception ex){throw new SQLException("Connect database failed!");}
		try
		{
			ps=con.prepareStatement(sql);
			ps.setInt(1,ID);
			int rowCount=ps.executeUpdate();
			if(rowCount==0)
			{
				throw new SQLException("Restor ClassTest failed!");
			}
		}
		catch(SQLException sqlex)
		{
			System.out.println("Restor ClassTest Error:"+sqlex.getMessage());
			throw new SQLException("Restor ClassTest Error");
		}
		finally
		{
			try{con.close();ps.close();}
			catch(SQLException sqlex){System.out.println("Restor Close ClassTest Error:"+sqlex.getMessage());}
		}
	}
	public void checkActivated()throws SQLException //检查是否有激活的试卷
	{
		sql="select count(ID) from ClassTest where State='2'"+(this.TeacherID==0?"":"  and TeacherID="+this.TeacherID);
		Connection con;
		Statement ps=null;
		try{con=db.connectToDB();}
		catch(Exception ex){throw new SQLException("Connect database failed!");}
		try
		{
			ps=con.createStatement();
			ResultSet rs=ps.executeQuery(sql);
			rs.next();
			int rowCount=rs.getInt(1);
			System.out.println(rowCount);
			if(rowCount!=0)
			{
				throw new SQLException("系统检测到尚有激活试卷,请确定没有激活的试卷后再退出!");
			}
		}
		catch(SQLException sqlex)
		{
			System.out.println("Restor ClassTest Error:"+sqlex.getMessage());
			throw new SQLException(sqlex.getMessage());
		}
		finally
		{
			try{con.close();ps.close();}
			catch(SQLException sqlex){System.out.println("Restor Close ClassTest Error:"+sqlex.getMessage());}
		}
	}
}

⌨️ 快捷键说明

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