我现在正在做考试抽题那一块,有些东西还是不解,我想问一下.我用java将数据库连接起来,利用数据库的查询语句将题库中的题按照某种规则一批批的调出来,然后再该怎么 放,而且我还想问的是我刚才从数据库中取得的只有题,并没有选项之类的,现在我该利用什么方法,将其中的选项也取出来和题干放到一块.

解决方案 »

  1.   

    确实有关联.但我不知道这么样写对不对.
    但我不知道怎么放.我写的程序也不知道对不?
    public ActionForward test(ActionMapping actionMapping,
                                 ActionForm actionForm,
                                 HttpServletRequest request,
                                 HttpServletResponse response) {
         ExamPaperDto examPaperDto = new ExamPaperDto();
         HttpSession session = request.getSession();
         try {
           String studentNo = "";
           if (session.getAttribute("UserId") != null &&
               !session.getAttribute("UserId").equals("")) {
             studentNo = session.getAttribute("UserId").toString();
           }
           request.setAttribute("studentNo", studentNo);
     
           if (studentNo == null || studentNo.equals("")) {
                      studentNo = "t001";
           }
           String ruleNo = request.getParameter("flowNo");
           BbsUserinfoDelegate delegate = new BbsUserinfoDelegate();
           BbsUserinfoDto dto = delegate.bbsUserinfoFindByPrimaryKey(studentNo);
           String type = dto.getLoginType();
           TestRuleDelegate testRuleDelegate = new TestRuleDelegate();
            TestRuleDto testRuleDto = testRuleDelegate.testRuleFindByPrimaryKey(
               ruleNo);
           String testTime = testRuleDto.getTestTime();
           RuleDetailDelegate ruleDetailDelegate = new RuleDetailDelegate();
           RuleDetailDto[] ruleDetailDtos = ruleDetailDelegate.
               ruleDetailFindBytesRuleID(tesRuleID);
           String[] types = new String[ruleDetailDtos.length];
           String[] sectionNos = new String[ruleDetailDtos.length];
           Integer[] numbers = new Integer[ruleDetailDtos.length];
           //创建test记录
           String flowNo = GetKey.GetKeys("fl");
           request.setAttribute("flowNo", flowNo); //将TestDto的flowNO的值返回给前台页面
           TestDto testDto = new TestDto();
           ExamQuestionDto examQuestionDto = new ExamQuestionDto();
           testDto.setStudentNo(studentNo);
            testDto.setFlowNo(flowNo);
           testDto.setTimelimit(new Integer(testTime));
           testDto.setPaperNote(testRuleDto.getName());
           testDto.setFinishTime(new Timestamp(System.currentTimeMillis()));
           TestDelegate testDelegate = new TestDelegate();
           testDelegate.createTest(testDto);
           request.setAttribute("testDto", testDto);
           for (int i = 0; i < ruleDetailDtos.length; i++) {
             types[i] = ruleDetailDtos[i].getType();
             sectionNos[i] = ruleDetailDtos[i].getSectionID();
             numbers[i] = ruleDetailDtos[i].getAmount();
             try {
               Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
               Connection con = DriverManager.getConnection(address, user, passwd); //建立链接
               con.setCatalog(database); //确定目标数据库
               Statement stmt = con.createStatement();
               ResultSet rs = stmt.executeQuery
                   (" select top numbers[i] * from Question where Exercisetype ='" +
                    types[i] +
                    "' AND SectionNo='" + sectionNos[i] + "'order by newid()");
               String question = "";
               String exerciseType = "";
               while (rs.next()) {
                 question = rs.getString("question");
                 exerciseType = rs.getString("ExciseType");
                 examQuestionDto.setExerciseID(questionDto.getExerciseID());
                 examQuestionDto.setExerciseType(questionDto.getExerciseType());
                 String question = questionDto.getQuestion();
                 if (question.length() > 800) {
                   question = parsehtml(question);
                 }
                 examQuestionDto.setQuestionText(question);
                 examQuestionDto.setScore(questionDto.getScore());
                 if (exerciseType.equals("S")) {
                   //查找选项
                   try {
                     SelectAnswerDelegate selectAnswerDelegate = new
                         SelectAnswerDelegate();
                     SelectAnswerDto[] selectAnswerDtos = selectAnswerDelegate.
                         selectAnswerFindByExerciseID(questionDto.getExerciseID());
                     examQuestionDto.setSelectOptions(selectAnswerDtos);
                   }
                   catch (Exception e) {
                     e.printStackTrace();
                   }
                   //加入到list中
                   examPaperDto.getSingleList().add(examQuestionDto);
                 }
                 else if (exerciseType.equals("J")) {
                   examPaperDto.getJudgeList().add(examQuestionDto);
                 }
                 else return null;
                 return examPaperDto;
               }
               stmt.close();
               rs.close();
               con.close();
               return vc;
             }
             catch (SQLException e1) {
               e1.printStackTrace();
               return null;
             }
             catch (ClassNotFoundException e1) {
               e1.printStackTrace();
               return null;
             }
           }
               request.setAttribute("examPaperDto", examPaperDto);
           catch (Exception e) {
             //    e.printStackTrace();
             request.setAttribute("message", "登录超时,请重新登陆!");
             return actionMapping.findForward("error");
           }
     
         }
      

  2.   

    这里面的程序还有一些没有写完,Ruletali是规则细节.TestRule是考试规则.