开发者

How to display next record from database

开发者 https://www.devze.com 2023-02-03 10:59 出处:网络
try { if ( rs.next( ) ) { int id_col = rs.getInt(\"ID\"); String id = Integer.toString(id_col); String first = rs.getString(\"First_Name\");
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

精彩评论

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