Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

Next Button for Java MySQL

dontenter

Novice
Advanced Member
Messages
36
Reaction score
0
Points
26
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())
 
Last edited:
hindi mo sinosort?

select * from table limit (n) offset (n) rows

https://www.petefreitag.com/item/451.cfm

Thanks po sa reply. di ko pa po na tatry yung ganyang query, pero kung sa pagkakaintindi ko, pwede ko gawaing limit 1 lang para paisa isa lang yung pag kuha sa database? tama po ba?

sinubukan ko, tingin ko wala sa mySQL query yung need ko i add sa code ko =<
 
Last edited:
DId you test your sql query string using the command prompt to make sure you're getting the result you want? I don't see anything wrong with the code so I'm assuming the query result might be incorrect.
 
Last edited:
Hi calbee,

The query was fine and I'm getting the correct results, it just, I assume that it's getting all the rows immediately and not one by one. Is there a query that will only retrieve a row of the mySQL dynamically?
 
IF you just need the first row you can use the LIMIT 1 clause. It's actually more efficient that way since you let the database narrow down the result for you.
 
Back
Top Bottom