java随机组卷代码 java 随机

如何用Java实现随机出题?import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import oracle.jdbc.driver.OracleDriver;
public class GenPaperServlet extends HttpServlet
{
Connection conn;
Statement stmt;
ResultSet rs;
int total_question_num;
int total_question_in_paper;
int total_paper_num;
String curr_classid;
public GenPaperServlet()
{
conn = null;
stmt = null;
rs = null;
total_question_num = 0;
total_question_in_paper = 0;
total_paper_num = 0;
curr_classid = "";
}
public void doGet(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
throws ServletException, IOException
{
httpservletresponse.setContentType("text/html;charset=GBK");
PrintWriter printwriter = httpservletresponse.getWriter();
printwriter.println("htmlhead/headbodycenter");
printwriter.println("请以POST方式提交");
printwriter.println("/center/body/html");
printwriter.close();
}
public void doPost(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
throws ServletException, IOException
{
httpservletresponse.setContentType("text/html;charset=GBK");
PrintWriter printwriter = httpservletresponse.getWriter();
String s = httpservletrequest.getParameter("classid");//"20"
String s1 = httpservletrequest.getParameter("paper_num");//"1"
if(s == null || s1 == null)
{
printwriter.println("center");
printwriter.println("请按照正常方式提交数据br");
printwriter.println("a href=https://www.04ip.com/test/admin/genpaper.jsp单击这里设置生成试卷java随机组卷代码的参数/a");
printwriter.println("/center");
}
total_paper_num = Integer.parseInt(s1);
curr_classid = s;
int i = 0;
if(!open_db(curr_classid))
{
printwriter.println("打开数据库错误!");
return;
}
if(!setParams(curr_classid))
{
System.out.println("设置系统参数错误!");
return;
}
if(!verify_QuertionLib())
{
printwriter.println("试题库中试卷不足java随机组卷代码,请增加新的试题!");
printwriter.println("班级代号java随机组卷代码:" + curr_classid);
printwriter.println("该班级一套试卷中的试题数:" + total_question_in_paper);
printwriter.println("目前题库中该班级的试题总数:" + total_question_num);
return;
}
i = genPaper(total_paper_num, curr_classid);
if(i == 0)
{
printwriter.println("生成试卷操作失败!");
return;
}
if(!updateOtherTable(i, curr_classid))
{
printwriter.println("更新相关表操作失败!");
return;
} else
{
printwriter.println("center");
printwriter.println("动态组卷成功!br");
printwriter.println("共生成java随机组卷代码了 " + i + " 套试卷br");
printwriter.println("a href=https://www.04ip.com/test/admin/genpaper.jsp单击这里设置生成试卷的参数/a");
printwriter.println("/center");
return;
}
}
public boolean open_db(String s)
{
try
{
new OracleDriver();
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ora9", "scott", "tiger");
stmt = conn.createStatement();
}
catch(Exception exception)
{
return false;
}
return true;
}
public boolean setParams(String s)
{
String s1 = "";
try
{
String s2 = "select count(questionid) as countquestionidfrom test_question_lib ";
s2 = s2 + "where classid='" + s + "'";
rs = stmt.executeQuery(s2);
rs.next();
total_question_num = rs.getInt("countquestionid");

推荐阅读