D
D
de_iiah_teji9_iiace2016-02-01 10:59:32
MySQL
de_iiah_teji9_iiace, 2016-02-01 10:59:32

Why is it not displaying data from the table?

I want to display a row with the user id from the table

public static void getUserId(Label label) throws SQLException {
        Statement st = null;
        ResultSet rs = null;

        String selectId = "SELECT user_id FROM users;";

        try {
            st = conn.createStatement();
            rs = st.executeQuery(selectId);
            while(rs.last()) label.setText("ID: " + rs.getString(1));
        }
        catch (SQLException e){
            e.printStackTrace();
        }
    }

and then I call the method in the controller, but the label still remains empty. What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Fedotov, 2016-02-02
@ColorCast

Check:

  • Is the request in progress
  • Get the count of the returned collection and throw an Exception if it is less than the expected value
  • Handle exceptions in a loop (at a glance, the dragon is hiding there)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question