1

I'm trying to debug my prepared statement in java and I'm stuck on this checkEmail function that I implemented. When I go into debugging and it reaches the setString line, it shows NOT SPECIFIED in place of the '?'. If I hardcode 'findEmail' into the String query it will work and find the email. Here is the piece of code:

public static boolean checkEmail(String findEmail) {
    Connection conn = EstablishConnection.conn;
    boolean found = false;
    try {
        String query = "SELECT email FROM customers WHERE email=?";
        Logging.debug(query);
        PreparedStatement preparedStatement = conn.prepareStatement(query);
        preparedStatement.setString(1,findEmail);
        ResultSet rs = preparedStatement.executeQuery(query);
        //Iterate through the results of the query
        if (rs.next()) {
            found = true;
        }
        preparedStatement.close();
    } catch (Exception e) {
        Logging.debug("Exception thrown in CustomerOperations.getCustomerInfo(): " + e.getMessage());
        e.printStackTrace();
    }
    return found;

}
MeesterMarcus
  • 700
  • 1
  • 9
  • 25

1 Answers1

2

Try to replace this :

  ResultSet rs = preparedStatement.executeQuery(query);

With:

  ResultSet rs = preparedStatement.executeQuery();

Because you had already pass the query to prepareStatement : conn.prepareStatement(query);

Abdelhak
  • 8,299
  • 4
  • 22
  • 36