从我的sqlit数据库中没有检索到任何数据? [英] No data are retrieved from my sqlit data base ?

查看:96
本文介绍了从我的sqlit数据库中没有检索到任何数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的sqlite数据库表中检索数据,该表是MealFood及其包含以下内容:日期时间meal_type,Food_id.当我成功插入数据并确保通过日志进行插入时,但是当我试图从中检索数据时,光标将返回空

创建MealFood声明

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) {
			cursor.moveToFirst();
		}
		return cursor;
}




我使用getSpecificMealFoodsID(String date,String mealType)的代码




the code where i use the getSpecificMealFoodsID(String date,String mealType)

     int food_id;
     int [] foods_ID;
DBAdapter dbAdapter = new DBAdapter(this);
dbAdapter.open();
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+" ");
             foods_ID[i]=food_id;
             i++;
            }

       while (BFMeal_foods_c.moveToNext());
     }


    BFMeal_foods_c.close();
    BFMeal_foods_c.deactivate();
    dbAdapter.close();



如果成功插入表并且可以从数据库中的其他表中检索数据,为什么当我尝试从该表中检索数据时,光标返回空?检索方法有问题吗?有时它给我一个例外,说有一个数据库对象"没有关闭的游标,但是我关闭了游标,没有游标被打开但没有关闭.为什么自从我关闭游标后会发生此异常?请任何机构可以帮助我

任何帮助将不胜感激...
在此先感谢



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

推荐答案

我希望它将对您有所帮助.
试试这个教程...

点击此处
I hope it will help you.
Try this Tutorial...

Click Here


这篇关于从我的sqlit数据库中没有检索到任何数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆