Cómo mostrar el siguiente registro de la base de datos

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 this code .. it only shows the first record.

preguntado el 09 de enero de 11 a las 06:01

Hi mimi - you need to accept some more of the answers people have been giving you. Also some more detail would be good. What language is this in? What do you mean by next record? At the moment you're only getting a single record once, (see my answer). Do you want to get each of them one by one? -

Also please pay more attention when you choose tags... this is Java not jQuery or JavaScript. -

2 Respuestas

intenta usar

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");

    ......
}

Espero que esto ayude.

Respondido el 09 de enero de 11 a las 11:01

Assuming you want to loop through and show them all one by one, you'll need to use a loop.

Estás usando un if declaración sobre el 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.

Respondido el 09 de enero de 11 a las 09:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.