JavaMySQL下一步按钮

JavaMySQL下一步按钮,java,mysql,arraylist,next,listiterator,Java,Mysql,Arraylist,Next,Listiterator,我需要在java中使用next按钮逐个显示mySQL数据库的行。但我很难做到这一点 下面是我目前的代码。我知道Arraylist和ListIterator应该分开,但我不知道应该放在哪里,因为我也需要它们在我的结果集中 JButton btnSubmit = new JButton("Next"); btnSubmit.addActionListener(new ActionListener() { public void actionPerformed(ActionEv

我需要在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());
                          }
                }

您是打算在每次单击按钮时运行SQL查询,还是计划实现某种分页?也许SQL查询只能运行一次。我的主要目的是将数据库中的列显示到我的文本字段中,并使用“下一步”按钮移动到下一行。如果结果集相对较小,则应该在其他地方执行查询。只需在上述方法中对集合进行迭代。您是否愿意为我编写一个指导代码?您是打算在每次单击按钮时运行SQL查询,还是计划实现某种分页?SQL查询可能只能运行一次。我的主要目的是将数据库中的列显示到我的文本字段中,并使用“下一步”按钮移动到下一行。如果结果集相对较小,则应该在其他地方执行查询。只需在上述方法中迭代集合。您能为我编写一个指导代码吗?