java mysql下一步按钮

w51jfk4q  于 2021-06-24  发布在  Mysql
关注(0)|答案(0)|浏览(253)

我需要在java中使用next按钮逐个显示mysql数据库的行。但我很难做到。
下面是我目前的代码。我知道arraylist和listiterator应该分开,但是我不知道应该放在哪里,因为我也需要它们在我的结果集中。

JButton btnSubmit = new JButton("Next");
    btnSubmit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) { 

             try{
                    Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/anonymization", "root", "password");
                    Statement statement = connect.createStatement();
                    String examNames = textExamName.getText();
                    int examNumber = Integer.parseInt(textNumber.getText());                    
                    String selectTable = "Select number, content, choiceA, choiceB, choiceC, choiceD, correctans, * FROM " +examNames+"";               
                    ResultSet examresults = statement.executeQuery("Select * FROM " +examNames+"");             

                while(examresults.next()){
                    ArrayList numbers = new ArrayList();
                    ArrayList contents = new ArrayList();
                    ArrayList A = new ArrayList();
                    ArrayList B = new ArrayList();
                    ArrayList C = new ArrayList();
                    ArrayList D = new ArrayList();
                    ArrayList ans = new ArrayList();
                    ListIterator numberIterator = numbers.listIterator();   
                    ListIterator  contentIterator = contents.listIterator();
                    ListIterator  AIterator = A.listIterator();
                    ListIterator  BIterator = B.listIterator();
                    ListIterator  CIterator = C.listIterator();
                    ListIterator  DIterator = D.listIterator();     

                    numbers.add(examresults.getInt("number"));
                    contents.add(examresults.getString("content"));
                    A.add(examresults.getString("choiceA"));
                    B.add(examresults.getString("choiceB"));
                    C.add(examresults.getString("choiceC"));
                    D.add(examresults.getString("choiceD"));
                    ans.add(examresults.getString("correctans"));

            if (numberIterator.hasNext() && contentIterator.hasNext() && AIterator.hasNext() && BIterator.hasNext() 
                                && CIterator.hasNext() && DIterator.hasNext()) {                     
                            textAreaQuestion.setText(contentIterator.next().toString());
                          }
                }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题