How can I sort a MySQL Table to match "UUID", "Integer"?

Discussion in 'Plugin Development' started by xpaintall, Sep 11, 2021.

  1. Offline

    xpaintall

    So basically I'm creating a top 10 (For the highest amount of an integer) with ArmorStands.
    The armorstands spawn and everything works fine, until I see what's on the leaderboard. Instead of showing the players with the highest amount of the integer, it just shows the UUID's sorted alphabetically without the Integer being a factor.

    I hope you understand what I mean.

    Code:
        private void update() {
       // this is the code I use to update the ArmorStands
            Connection connection = f.SQL.getConnection();
    
            try {
                PreparedStatement p = connection.prepareStatement("SELECT * FROM Tokens ORDER BY 'TOKENS','UUID' DESC LIMIT 10");
                ResultSet results = p.executeQuery();
                int i = 0;
                while(results.next()) {
                    armorStands.get(i).setCustomName(ChatColor.AQUA + "" + (i+1) + ChatColor.GOLD + results.getString("UUID") + " - " + results.getInt("TOKENS"));
                    i++;
                }
    
                for(; i<10;i++) {
                    armorStands.get(i).setCustomName(ChatColor.GRAY + "Loading...");
                }
            }catch (SQLException e) {
                e.printStackTrace();
            }
    
        }
     

    Attached Files:

  2. Offline

    timtower Administrator Administrator Moderator

    @xpaintall Considered putting the query in your database program?
    So you can debug the query?
     

Share This Page