这里的语法错误到底是什么?使用原始查询我想检查数据库中是否存在电子邮件和密码
what exactly is the syntax error here ? using raw query I want to check email and password exist or not in database
我正在检查用户输入的密码和电子邮件是否存在于数据库中
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;
错误:
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
为了在 where
子句中有多个条件,您需要使用 AND
,替换
" WHERE " + col_2 + " = " +email+ " WHERE " + col_3 + "=" +password;
使用 where col2=email AND col3=password
(当然格式正确
这里有一个link可以帮助大家更好地理解Multiple Conditions in Where Clause也说明了如何使用AND
&OR
(where子句中的多个条件)
您使用了两次 WHERE,第二次 WHERE 必须用 AND 代替,并且电子邮件和密码也应该用单引号引起来。这是修改后的代码,包含我写的所有建议。
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;
我正在检查用户输入的密码和电子邮件是否存在于数据库中
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;
错误:
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
为了在 where
子句中有多个条件,您需要使用 AND
,替换
" WHERE " + col_2 + " = " +email+ " WHERE " + col_3 + "=" +password;
使用 where col2=email AND col3=password
(当然格式正确
这里有一个link可以帮助大家更好地理解Multiple Conditions in Where Clause也说明了如何使用AND
&OR
(where子句中的多个条件)
您使用了两次 WHERE,第二次 WHERE 必须用 AND 代替,并且电子邮件和密码也应该用单引号引起来。这是修改后的代码,包含我写的所有建议。
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;