[英]Failed to Login using sqllite
我是android开发的新手。 因此,我试图使用Sqlite作为数据库来实现注册和登录页面。 但是写完数据库代码和登录活动代码之后。 登录后,它不是执行登录后的其他活动,而是执行else代码。 看看下面的代码
数据库代码
//Check if user exist from Database
public boolean checkUser(String email, String password) {
//array of columns to fetch
String[] columns = {Constant.USER_ID};
SQLiteDatabase db = this.getReadableDatabase();
//selection Criteria
String selection = Constant.USER_EMAIL + " =?" + " AND " + Constant.USER_PASSWORD + " =?";
//selection argument
String[] selectionArgs = {email, password};
//Query user table with conditions
Cursor cursor = db.query(Constant.USER_TABLE_NAME, columns, selection, selectionArgs, null,null,null);
int cursorCount = cursor.getCount();
cursor.close();
db.close();
if (cursorCount > 0) {
return true;
}
return false;
}
登录活动代码
private void proceedToLogin(String email, String password)
{
boolean login = myDb.checkUser(email, password);
if (login) {
proceedToDashBoard();
}
else {
Toast.makeText(this, "Failed to login", Toast.LENGTH_SHORT).show();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.