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
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 + "'"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.