我正在使用 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();
}
}