Solved Help with Mysql

Discussion in 'Spigot Plugin Development' started by craftmen0202, Apr 3, 2020.

  1. Hello, I would like to know if there is any method for me to get how many players there are in a column in mysql, for example, we have a plugin that saves all the players that entered the server, how I would get how many players have already been placed on the table.
  2. Query "SELECT COUNT(*) FROM table;" should do it.
  3. Make sure that you have a MySQL-Class in your project. This should be contains the following:
    Code (Java):
        public static ResultSet getResult(String qry) {  
                try {
                    return con.createStatement().executeQuery(qry);
                } catch (SQLException e) {
            return null;
    And as the qry-param user the Query-String from above.

    So your method to get the Playercount would looks like:
    Code (Java):
        public static int getPlayerCount() {
            ResultSet rs = MySQL.getResult("SELECT COUNT(*) FROM table"); // Replace table to your tablename!
            try {
                while( return rs.getInt("COUNT(*)");
            } catch (SQLException e) {}
            return 0;
    If there are any questions left, you can ask me.
  4. Strahan


    Well, one would assume since he's already working with MySQL he knows how to implement a query.
    • Optimistic Optimistic x 1
  5. Hope so. The only reason I explained this was because he understands my method. Better safe than sorry :D
    • Like Like x 1
    • Agree Agree x 1
  6. Thank you very much, and I appreciate the kindness and calmness of explaining even though I don't need to.