Java MySQL Next按钮

时间:2016-10-05 11:31:54

标签: java mysql arraylist next listiterator

我需要使用java中的下一个按钮逐个显示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());
                          }
                }

0 个答案:

没有答案