Click here to Skip to main content
13,146,014 members (43,444 online)
Rate this:
Please Sign up or sign in to vote.
I am trying to retrieve data from my sqlite data base table which is MealFood and its contain : date time meal_type , Food_id . when i insert data its inserted successfully and i ensure that through the log but when iam trying to retrieve the data from it the cursor returns empty

create MealFood statement
private static final String MealFOOD_TABLE_CREATE= "create table IF NOT EXISTS MealFood (Date  text  not null , "+"Time   text not null,MealType  text not null,"+"Food_ID  integer   not null ,  primary key(Date,Time ,MealType,Food_ID) );" ;

retrieve method

<pre lang="java">
public Cursor  getSpecificMealFoodsID(String date,String mealType) throws SQLException
		Cursor cursor=db.query(MEALFOOD_TABLE_NAME, new String[]{KEY_MFFOODID},
	KEY_MFDATE+ " = '" + date + "'"+ " "+ "and" +" "+ KEY_MFMEALTYPE+ " = '" + mealType + "'", null, null, null, null,null);
		if (cursor != null) {
		return cursor;

the code where i use the getSpecificMealFoodsID(String date,String mealType)
         int food_id;
         int [] foods_ID; 
	DBAdapter dbAdapter = new DBAdapter(this);;
	String selected_date= date_btn.getText().toString();
    Cursor BFMeal_foods_c=dbAdapter.getSpecificMealFoodsID(selected_date,"Breakfast");
    Log.e("BFM_cursor",BFMeal_foods_c.getCount()+" ");//  it prints BFM_cursor  0
       foods_ID=new int[BFMeal_foods_c.getCount()];
        int i =0;
        if (BFMeal_foods_c.moveToFirst())
            do {
                 food_id= BFMeal_foods_c.getInt(0);
                 Log.e("food_ID",food_id+" ");
           while (BFMeal_foods_c.moveToNext());


if the insert to the table is done successfully and i can retrieve data from the other tables in my data base , why when i tried to retrieve the data from this table the cursor returned empty ? is there problem in the retrieve method ? and in some times it give me an exception saying that there is " data base object" a cursor not closed but i closed the cursor and there is no cursor i was opened and didn't close it . why this exception occur ,since i closed the cursor ?please any body can help me

any help would be appreciated ...
thanks in advance
Posted 17-Jun-12 1:37am
Updated 17-Jun-12 1:38am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I hope it will help you.
Try this Tutorial...

Click Here

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170915.1 | Last Updated 1 Aug 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100