Cursor is always returning null even if the database is not empty. Why? and how to solve that? Thank you.
public StatParcours getOneUserInfo(int id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_USER, new String[] { KEY_USER_ID,
KEY_STUDN , KEY_STUDBD, KEY_TEACHN, KEY_TEACHBD}, KEY_USER_ID + "=?",
new String[] { String.valueOf(id) }, null, null, null, null);
StatParcours stat = null;
if ((cursor!= null)&&(cursor.moveToFirst())){
stat = new StatParcours(
Integer.parseInt(cursor.getString(0)),
cursor.getString(1),
cursor.getString(2),
cursor.getString(3),
cursor.getString(4));
}
return stat ;
}
You are comparing the user ID against a string value, which will never succeed if your user IDs are numbers.
In Android, you should use query parameters only for string values; you should embed integers directly into the query string:
cursor = db.query(..., ..., KEY_USER_ID + "=" + id, null, ...);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With