我正在使用databaseutils 在我的数据库上运行SQL 查询。基本上只是一个登录,但是我想获取登录者的用户ID,所以我选择它。有结果就很好,没有结果就倒下。是否有办法设置 if is set 或类似的?
if(String.valueOf(loginCount).equals("2")) {
File dbfile = new File(Global.StaticDB + "/Users" );
SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbfile, null);
String loginQueryCheck=(String)DatabaseUtils.stringForQuery(db,"SELECT UserID from Users where Username like '" + txtUsername.getText().toString() + "' AND Password like '" + txtPassword.getText().toString() + "'",null);
Log.e("Login Query:", loginQueryCheck);
db.close();
if(loginQueryCheck.length() > 1) {
Context context = getApplicationContext();
CharSequence text = "Logged In";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
Intent ShowMainPage = new Intent(view.getContext(), MainPage.class);
startActivityForResult(ShowMainPage, 0);
} else {
Context context = getApplicationContext();
CharSequence text = "Login Failed";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}
最佳答案
将检查更改为:
if(loginQueryCheck != null && !loginQueryCheck.equals("") && loginQueryCheck.length() > 0)
关于java - Android SQLite 当没有结果时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12384719/