有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

JavaSwingforMySQL中的下一步按钮

显示数据库下一行的“下一步代码”按钮不会显示下一行,而是立即显示数据库的最后一行

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) 个答案