用于MySQL的Java swing中的下一个按钮

时间:2016-10-03 10:29:32

标签: java mysql swing

我的下一个显示数据库下一行按钮的代码不显示下一行,而是立即显示我数据库的最后一行。

JButton btnSubmit = new JButton("Submit");
    btnSubmit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            try{
                Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/anonymization", "root", "password");
                String examNames = textExamName.getText();
                String selectTable = "Select * FROM " +examNames+"";
                Statement statement = connect.createStatement();
                ResultSet examresults = statement.executeQuery(selectTable);
                if(examresults.next()){
                    String number = examresults.getString("number");
                    String content = examresults.getString("content");
                    String choiceA = examresults.getString("choiceA");
                    String choiceB = examresults.getString("choiceB");
                    String choiceC = examresults.getString("choiceC");
                    String choiceD = examresults.getString("choiceD");
                    textNumber.setText(number);
                    textAreaQuestion.setText(content);
                    textAreaA.setText(choiceA);
                    textAreaB.setText(choiceB);
                    textAreaC.setText(choiceC);
                    textAreaD.setText(choiceD);
                }
                else{
                        JOptionPane.showMessageDialog(null, "last record");
                    }


            }catch(Exception e){
                e.printStackTrace();
            }
        }
    });
    btnSubmit.setBounds(309, 483, 89, 23);
    contentPane.add(btnSubmit);

0 个答案:

没有答案