skip to Main Content

I am checking both the password and email enter by the user is exist in the database or not

String queryEmail="SELECT * FROM " + TABLE_NAME + " WHERE " + col_2 + " = " +email+ " WHERE " + col_3 + "=" +password;
        Cursor cr=db.rawQuery(queryEmail,null);
        if(cr.moveToFirst())

        {
            return true;
        }
        else
            return false;

ERROR:

Process: com.hfad.projectwithsql, PID: 4782
    android.database.sqlite.SQLiteException: near "WHERE": syntax error (code 1): , while compiling: SELECT * FROM Employee  WHERE EMPLOYEE_EMAIL = 12 WHERE EMPLOYEE_PASSWORD=1234

2

Answers


  1. For having multiple conditions in where clause you need to use AND, replace

    " WHERE " + col_2 + " = " +email+ " WHERE " + col_3 + "=" +password;
    

    With where col2=email AND col3=password (with correct formatting of course

    here is a link to help you understand better Multiple Conditions in Where Clause also explains how to use AND & OR (multiple conditions in where clause)

    Login or Signup to reply.
  2. You were using WHERE twice, the second WHERE has to be replaced by AND, and also email and password should be passed in single quote. Here is modified code with all suggestions I wrote.

    String queryEmail="SELECT * FROM " + TABLE_NAME + " WHERE " + col_2 + " = '" +email+ "' and " + col_3 + "='" +password+'"; 
    Cursor cr=db.rawQuery(queryEmail,null); 
    if(cr.moveToFirst())
    {
      return true;
    }else
      return false;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search