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

📄 test.java

📁 jsp+javabean的一个在线考试系统的设计(包含教学文档)
💻 JAVA
字号:
package tom;

import java.sql.*;
import java.io.*;
import java.util.Random;
import java.util.Arrays;

public class Test{
	
	private static int[] csubID=new int[20];
	private static int[] jsubID=new int[20];
	private static int subnum1,subnum2;
	private static int camount;
	private static int jamount;
	
	
	//Random rad=new Random();
	Connection con=null;
	Statement st=null;
	ResultSet rs=null;
	
	public Test(){
		try{
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		}
		catch(ClassNotFoundException e){
		}
	}

   public void setCsubid(int getc[]){
		for(int i=0;i<getc.length;i++){
			csubID[i]=getc[i];
		}
	}
	
	public int[] getCsubid(){
		return this.csubID;
	}
	
    public void setJsubid(int getj[]){
		for(int i=0;i<getj.length;i++){
			jsubID[i]=getj[i];
		}
	}
	
	public int[] getJsubid(){
		return this.jsubID;
	}
	
    public void setSubnum1(int subnum1){
    	this.subnum1=subnum1;
    }
    
    public int getSubnum1(){
    	return this.subnum1;
    }
    
	public void setSubnum2(int subnum2){
    	this.subnum2=subnum2;
    }
    
    public int getSubnum2(){
    	return this.subnum2;
    }
    public void setCamount(int camount){
    	this.camount=camount;
    }
    
    public int getCamount(){
    	return this.camount;
    }
    
    public void setJamount(int jamount){
    	this.jamount=jamount;
    }
    
    public int getJamount(){
    	return this.jamount;
    }
    
    public void createCsub(int subnum1,int getc[],javax.servlet.jsp.JspWriter out){
    	try{
    		 con=DriverManager.getConnection("jdbc:odbc:grad","xiaoyan","");
		     PreparedStatement pstmSelect=con.prepareStatement("SELECT * FROM choice WHERE cid=?");
		     try{
		     	    out.print("p><br>选择题:");
					for(int i=0;i<subnum1;i++){
					                 int y=getc[i];
									 int j=i+1;
					                 pstmSelect.setString(1,Integer.toString(y));
									 rs=pstmSelect.executeQuery();
									 if(rs.next()){
									 	    out.print(+j+"、"+rs.getString("csub"));
									 	    
									 	    
									        out.print("<br>"+rs.getString("canswer"));
									        out.print("<hr>");
									 }
									 
					}
					
		     }
		     catch(IOException e){
		     }
		     rs.close();
		     pstmSelect.close();
    	}
    	catch(SQLException e){
    	}
    	finally{
		           try{
				            if(con!=null)
							           con.close();
				   }
				   catch(SQLException e){}
		 }
    
    }
    
    public void createJsub(int subnum2,int getj[],javax.servlet.jsp.JspWriter out){
    	try{
    		con=DriverManager.getConnection("jdbc:odbc:grad","xiaoyan","");
			PreparedStatement pstmSelect1=con.prepareStatement("SELECT * FROM judge WHERE jid=?");
			try{
				out.print("<br>判断题:<p>");
				for(int i=0;i<subnum2;i++){
				    int z=getj[i];
					int j=i+1;
					pstmSelect1.setString(1,Integer.toString(z));
					rs=pstmSelect1.executeQuery();
					if(rs.next()){
						out.print(j+"、"+rs.getString("jsub"));
						out.print("<hr>");
						}
											
					}
					
			}
			catch(IOException e){
			}
			rs.close();
			pstmSelect1.close();
    	}
    	catch(SQLException e){
    	}
    	 finally{
		           try{
				            if(con!=null)
							           con.close();
				   }
				   catch(SQLException e){}
		 }
    }
   public String[] ckey(){
   	   String ckey[]=new String[subnum1];
   	   try{
   	   	   con=DriverManager.getConnection("jdbc:odbc:grad","xiaoyan","");
		   PreparedStatement pstmSelect=con.prepareStatement("SELECT * FROM choice WHERE cid=?");
		   for(int i=0;i<subnum1;i++){
		   	     int j=csubID[i];
		   	     pstmSelect.setString(1,Integer.toString(j));
		   	     rs=pstmSelect.executeQuery();
		   	     if(rs.next()){
		   	     	ckey[i]=rs.getString("ckey"); 
		   	     	}
		   }
   	   }
   	   catch(SQLException e){
   	   }
   	   return ckey;      
   } 

   public String[] jkey(){
   	   String jkey[]=new String[subnum2];
   	   try{
   	   	   con=DriverManager.getConnection("jdbc:odbc:grad","xiaoyan","");
		   PreparedStatement pstmSelect=con.prepareStatement("SELECT * FROM judge WHERE jid=?");
		   for(int i=0;i<subnum2;i++){
		   	     int j=jsubID[i];
		   	     pstmSelect.setString(1,Integer.toString(j));
		   	     rs=pstmSelect.executeQuery();
		   	     if(rs.next()){
		   	     	jkey[i]=rs.getString("jkey"); 
		   	     }
		   }   
   	   }
   	   catch(SQLException e){
   	   }
   	   return jkey;
   }
}

⌨️ 快捷键说明

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