我无法弄清楚如何从数据库中提取这些数据

时间:2016-10-14 09:28:33

标签: java mysql sql multidimensional-array javafx

如何将这三行(问题,选择和答案)放入三维数组或数组列表中。如果它是一个三维数组,问题行将在一个数组中,选择行将在另一个数组中,答案行将在第三个数组中,或者如果它是一个数组列表,如何我是否坚持选择,而我却没有完全明白如何做到这一点。 这就是我所做的

//this display all the  questions for the students to answer
 public List<Students> displayAllQuestionsForAnswer()throws DBException{

        List<Students>questions = null;
        ResultSet rs = null;
        String query = "SELECT questions, choicea, choiceb, "
                + "choicec, choiced,answers FROM quesans " +
                "WHERE assignment.subject_name = quesans.subject_id " +
                "AND assignment.year = quesans.year_id LIMIT 50";

        Connection conn = DBUtil.getConnection();

        try(PreparedStatement ps = conn.prepareStatement(query)){

            questions =  new ArrayList<Students>();
            ps.setString(1, query);
            rs = ps.executeQuery();

            while(rs.next()){

                query.add(new Students(
                        rs.getString("questions");
                ));
               /* for(int i = 1; i < rs.next(); i++){

                }*/
               /*if(rs.next()< 50){
                   questions++;
               }*/
            }
            return questions;
        }catch(SQLException e){
            throw new DBException (e);
        }
    }

我只是觉得不那么多。任何协助将不胜感激

0 个答案:

没有答案