This method is in databasehelperclass returning single value expected
public Cursor getUserDataFromDb(){
SQLiteDatabase sqLiteDatabase=this.getWritableDatabase();
Cursor rawdata=sqLiteDatabase.rawQuery("SELECT NAME FROM " +TABLE_NAME+" ORDER BY ID DESC LIMIT 1)",null);
return rawdata;
}
fetching value from usertable inside an Activity
try {
Cursor cursor = mydb.getUserDataFromDb();
if (cursor.moveToFirst()){
name_resultfromdb = cursor.getString(0);
}
else {
Toast.makeText(this,"Setup your Account",Toast.LENGTH_LONG).show();
}
}catch (Exception e){
e.printStackTrace();
}
I am using the above code to get the data, but I am getting null.
I want to show this value into a TextView, but I am unable to get it.
There is a helper function to read a single value:
String result = DatebaseUtils.stringForQuery(db,
"SELECT NAME FROM "+TABLE_NAME+" ORDER BY ID DESC LIMIT 1", null);
Anyway, if this query does not return a value, then the table is empty, or the value in the Name column of the last record is empty.
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