Exemplo n.º 1
0
 public void displayQuizOptions() {
   // displays the the quizzes the pupil can do based on their skill level
   int quizNum = 0;
   int total = 0;
   String quizSkill = "";
   try {
     DatabaseConnect.init();
     Connection conn = DatabaseConnect.getConnection();
     Statement stmt = conn.createStatement();
     String query = "SELECT * FROM QUIZ where QUIZ_LEVEL ='" + skillLevel + "'";
     ResultSet result = stmt.executeQuery(query);
     DefaultTableModel model = (DefaultTableModel) tblQuiz.getModel();
     while (model.getRowCount() > 0) {
       model.removeRow(0);
     }
     if (result != null) {
       while (result.next()) {
         quizNum = result.getInt("QUIZ_NUMBER");
         total = result.getInt("TOTAL_POINTS");
         quizSkill = result.getString("QUIZ_LEVEL");
         int number = NumQuestions(quizNum);
         model.addRow(new Object[] {quizNum, quizSkill, total, number});
       }
     }
     stmt.close();
     conn.close();
     result.close();
   } // end try
   catch (Exception ex) {
     System.err.print("SQLException: ");
     System.err.println(ex.getMessage());
   }
 } // END method
Exemplo n.º 2
0
 public int NumQuestions(int quizNum) {
   // return the number of questions there are in a particular quiz
   int numQuestions = 0;
   try {
     DatabaseConnect.init();
     Connection conn = DatabaseConnect.getConnection();
     Statement stmt = conn.createStatement();
     ResultSet result =
         stmt.executeQuery("SELECT * FROM QUIZ_QUESTIONS WHERE QUIZ_NUMBER=" + quizNum + "");
     if (result != null) {
       while (result.next()) {
         numQuestions++;
       }
     }
     stmt.close();
     conn.close();
     result.close();
   } // end try
   catch (Exception ex) {
     System.err.print("SQLException: ");
     System.err.println(ex.getMessage());
   }
   return numQuestions;
 }