Saturday 1 October 2016

Checking username and password in Android using SQLite database





I want to get query from SQLite Database in my APP that consist of name, surname, username and also password.



when I click login button, it made crash. here is my code ##



public String Login(String Username, String Password) {

String Q = "SELECT * FROM " + DBHelper.TBLname + " WHERE "
+ DBHelper.ColumnUser + " = " + Username
+ " AND " + DBHelper.ColumnPass + " = " + Password;


Cursor LoginQuery = MyDB.rawQuery(Q, null);

if (LoginQuery == null) {
LoginQuery.close();
String LoginResult = "Wrong User Name and Password";
return LoginResult;
}
LoginQuery.moveToFirst();
String LoginResult = LoginQuery.getString(3);
LoginQuery.close();

return LoginResult;
}

Answer



Try this without dbhelper:



SELECT * FROM YOUR TABLE WHERE Username=Your Username AND Password=Your Password

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...