Get all Rows from a query

Asked

Viewed 42 times

1

Friends, I have a little problem: I need to take each of the Rows of a query with a loop. I saw a code in Stackoverflow, but it doesn’t work. Anyone who knows how to do it, please let me know.

Follows the code:

ResultSet rs = conn.prepareStatement("SELECT * FROM `rankups`").executeQuery();

             do {

                 String nick = rs.getString("nick");
                 String rank = rs.getString("rank");
                 UUID uuid = Bukkit.getOfflinePlayer(nick).getUniqueId();
                 Rankupbr.DATA_YAML.set(uuid.toString(), rank);

                } while (rs.next());
  • 1

    What is the error of the code ?

1 answer

0


Try it like this:

ResultSet rs = conn.prepareStatement("SELECT * FROM `rankups`").executeQuery();

         while(rs.next()) {

             String nick = rs.getString("nick");
             String rank = rs.getString("rank");
             UUID uuid = Bukkit.getOfflinePlayer(nick).getUniqueId();
             Rankupbr.DATA_YAML.set(uuid.toString(), rank);

            }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.