[英]Query having 2 Where Clause
i am trying to login and want to validate username and password against the records in the database. 我正在尝试登录,并想针对数据库中的记录验证用户名和密码。 I am not sure how to pass two Where clause
我不确定如何通过两个Where子句
public Boolean login(String username, String password) throws SQLException {
Cursor mCursor = db.query(TABLE_USERS, new String[] { ID,
KEY_NAME, KEY_USERNAME}, KEY_USERNAME + "="
+ "'"+username+"'", KEY_PASSWORD + "="
+ "'"+password+"'", null, null, null, null, null);
if (mCursor.moveToFirst()) {
return true;
}
return false;
}
Am getting a Syntax Error. 正在收到语法错误。
不要使用两个where子句(在任何情况下我都不认为这是ANSI SQL允许的),请使用AND运算符将它们联接起来,使其看起来像:
KEY_NAME + " = '" + username + "' AND " + KEY_PASSWORD + " = '" + password + "'"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.