Reputation: 189
I try to pull data from database by using RawQuery method, but it seems I get empty rows. Actually data is present in the database which I am try to pull. Can anyone find my mistake?
db = dbhelper.getReadableDatabase();
String selectSQL = "Select * from " + Wish_list_Table.TABLE_NAME
+ " where " + Wish_list_Table.COL_CATEGORY + " = ?";
String[] add = { " HOME" };
TextView textView = getGenericView();
Cursor selectdata = db.rawQuery(selectSQL, add);
Log.i("select", "" + selectdata.getCount());
This class for database table property......
public static abstract class Wish_list_Table implements BaseColumns {
public static final String TABLE_NAME = "WISH_LIST1";
public static final String COL_NAME = "NAME";
public static final String COL_TIME = "TIME";
public static final String COL_DATE = "DATE";
public static final String COL_CATEGORY = "CATEGORY";
public static final String COL_DESC = "DESC";
}
this is DATABASE IMAGE...
Upvotes: 0
Views: 51
Reputation:
try some thing like the following :
String[] add = { "HOME" };
String [] columns = {"NAME" , "CATEGORY"};
Cursor cursor = db.query(Wish_list_Table.TABLE_NAME, columns, Wish_list_Table.COL_CATEGORY + " = ?", add, null, null, null)
while(cursor.moveToNext()){
String name = cursor.getString(cursor.getColumnIndex(ArrayList_table.COL_NAME));
textView.setText(name);
}
cursor.close();
but make sure the data in the database is present .
Upvotes: 0
Reputation: 38098
Look at this:
String[] add = { " HOME" };
Don't you see there's a SPACE before "HOME"? It will never match the values in the db!
So you'll always get an empty Cursor.
Replace that statement with this:
String[] add = { "HOME" };
And you'll get all the records where CATEGORY equals 'HOME'
Upvotes: 1