我想知道为什么这个方法总是空的ResultSet:
public boolean checkIfUsersExists(String email) throws SQLException {
String query = "SELECT * FROM users WHERE email= ?;";
PreparedStatement preparedStatement = getConnection().prepareStatement(query);
preparedStatement.setString(1, email);
log.info(preparedStatement.toString());
ResultSet resultSet = preparedStatement.executeQuery();
return resultSet.next();
}
这种方法效果很好:
public boolean checkIfUsersExists(String email) throws SQLException {
String query = String.format("SELECT * FROM users WHERE email='%s';", email);
log.info(query);
ResultSet resultSet = getConnection()
.createStatement()
.executeQuery(query);
return resultSet.next();
}
我需要使用PreparedStatement来避免SQL注入,但在这种情况下它不起作用。 我使用sqlite 3.21.0.1