Home > Net >  what exactly is the syntax error here ? using raw query I want to check email and password exist or
what exactly is the syntax error here ? using raw query I want to check email and password exist or

Time:09-29

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

CodePudding user response:

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)

CodePudding user response:

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;
  • Related