#How to display a list of database users?

32 messages · Page 1 of 1 (latest)

tough laurel
#

please tell me how to display a list of users in the form user@localhost, otherwise I display only the user's nickname

 public List<String> listUser(String value, List<String> list) throws SQLException {
        String query = MessageFormat.format("SELECT {0} FROM {1}.user", value, this.name);
        ResultSet resultSet = getConnect().createStatement().executeQuery(query);
        while (resultSet.next())
            list.add(resultSet.getString(value));

        return list;
    }
trim vaultBOT
#

This post has been reserved for your question.

Hey @tough laurel! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

tired stag
#

don't use MessageFormat for formatting SQL statements

#

instead, use prepared statements

tough laurel
tired stag
#

imagine value being something like 1;DROP DATABASE yourdb;-- - that would delete your database

#

just because someone would write weird stuff inside it

#

this problem is called SQL injection

#

And why do you need to perform such a weird sql statement?

tough laurel
tired stag
#

so?

#

why such a weird query?

tough laurel
# tired stag why such a weird query?

well, I didn’t find any options on the Internet to find out the users of the database, so I decided to take them from the table stored in the database itself

tough laurel
tired stag
tired stag
#

AHOW USERS?

#

SHOW USERS*

tough laurel
#

Can you please give an example of such a query?

tired stag
#

SHOW USERS

#

that's the sql query

#

or alternatively SELECT user FROM mysql.user

#

no weird substitutions

tough laurel
#

Can you please provide a link to a website?

tired stag
#

First googlecredult lmao

#

ResultSet resultset = getConnect().createStatemenr().executeQuery("SHOW USERS");

tired stag
#

try using SELECT user FROM mysql.user instead maybe

tough laurel