pacheck naman po kung anong mali sa codes ko. Imbes na next row po kasi yung madidisplay, nag jujump agad sa last row ng database ko.
code:
java mysql swing
My code for next button to display the next row of my database doesn't display the next row instead it immediately display the last row of my database.
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);
-nag try narin ako lagyan ng WHERE yung query ko. Hindi naman nag nenext. May mali po ba sa codes or sa process?
Edit: nagtry narin po pala ako na palitan yung if ng While(results.next())
code:
java mysql swing
My code for next button to display the next row of my database doesn't display the next row instead it immediately display the last row of my database.
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);
-nag try narin ako lagyan ng WHERE yung query ko. Hindi naman nag nenext. May mali po ba sa codes or sa process?
Edit: nagtry narin po pala ako na palitan yung if ng While(results.next())
Last edited: