M
M
Masteron2016-01-30 18:46:30
MySQL
Masteron, 2016-01-30 18:46:30

mysql and java registration?

I wrote the code:

private Boolean checkLogin() throws SQLException {
        String query="SELECT COUNT(*) FROM testtable WHERE LOGIN=?";
        PreparedStatement preparedStatement = DB.connection.prepareStatement(query);
        preparedStatement.setString(1,clientSend.getLogin());
        preparedStatement.execute();
       
       
    }

It is necessary to find out if the string is in the database in the LOGIN column, then the method will return true otherwise
false, how to implement it?
And yes, how to substitute variables in queries in java without using questions.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
angry_cellophane, 2016-01-30
@angry_cellophane

private Boolean checkLogin() throws SQLException {
        String query="SELECT COUNT(*) FROM testtable WHERE LOGIN= :login";
        PreparedStatement preparedStatement = DB.connection.prepareStatement(query);
        preparedStatement.setString("login", clientSend.getLogin());
        ResultSet resultSet = preparedStatement.executeQuery();
        if (!resultSet.next()) throw new RuntimeException();

        int count = resultSet.getInt(1);
        return count == 1;
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question