I’m using the databaseutils to run a SQL query on my database. Basically just a login, however I want to take the userid of the person who’s logged in so i’m selecting that. It works fine if theres a result, but falls over when theres no result. If there a way to set if is set or similar?
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();
}
}
change the check to: