Then the following must return the password of the user stored in the DB
public String getPasswordByUsername(String userName)
{
SQLiteDatabase db = this.getReadableDatabase();
String selectQuery = "SELECT * FROM " + TABLE_USERS + " WHERE "
+ KEY_USERS_USERNAME + " = " + userName;
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.getCount() < 1) {
cursor.close();
return "NOT EXIST";
}
cursor.moveToFirst();
String password = cursor.getString(cursor.getColumnIndex("password"));
cursor.close();
return password;
}
When I try to get the password of the user "w", I get:
12-24 10:54:23.639: E/AndroidRuntime(11237): FATAL EXCEPTION: main
12-24 10:54:23.639: E/AndroidRuntime(11237): Process: com.example.doit, PID: 11237
12-24 10:54:23.639: E/AndroidRuntime(11237): android.database.sqlite.SQLiteException: no such column: w (code 1): , while compiling: SELECT password FROM users WHERE username = w
How can I fetch the right password? Thank you.
Aucun commentaire:
Enregistrer un commentaire