开发者

How to display next record from database

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜