try {
if ( rs.next( ) ) {
int id_col = rs.getInt("ID");
String id = Integer.toString(id_col);
String first = rs.getString("First_Name");
String last = rs.getString("Last_Name");
String job = rs.getString("Job_Title");
textID.setText(id);
textFirstName.setText(first);
textLastName.setText(last);
textJobTitle.setText(job);
}
else {
rs.previous( );
JOptionPane.showMessageDialog(Workers.this, "End of File");
}
}
catch (SQLException err) {
JOptionPane.showMessageDialog(Workers.this, err.getMessage());
}
I can't get the next record when i use t开发者_如何学Pythonhis code .. it only shows the first record.
try using
while(rs.next())
{
int id_col = rs.getInt("ID");
String id = Integer.toString(id_col);
String first = rs.getString("First_Name");
String last = rs.getString("Last_Name");
String job = rs.getString("Job_Title");
......
}
Hope this helps.
Assuming you want to loop through and show them all one by one, you'll need to use a loop.
You're using an if
statement on the next
method, which will only get the next one and then stop. If you want to get each of them you need to do a loop.
精彩评论