gpt4 book ai didi

java - Android SQLite 当没有结果时

转载 作者:行者123 更新时间:2023-12-01 05:08:33 25 4
gpt4 key购买 nike

我正在使用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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com