0

我正在查询我的数据库。当我使用 int 作为选择部分时,我得到了我想要的返回信息。当我使用字符串进行选择时,我什么也没有返回。使用字符串时是否有不同的查询方式或者我做错了什么。这个函数在我传入一个 int 时起作用,但是当我传入一个字符串时它不起作用。我使用了断点,进入函数的参数是正确的,但它没有从数据库中检索数据。

这是代码

 public String childFound(String item_name)throws Exception
{

    Cursor c = db.query(DB_TABLE, new String[] { KEY_INSPECTION_ID, KEY_ITEM_NAME},
            "item_name="+ item_name, null, null, null, null);

       int id=c.getColumnIndex(KEY_ITEM_NAME);
        c.moveToFirst();
        String result=c.getString(id);
       c.close();
       return result;

}

如果我将 String item_name 更改为 int InspectionItem 它可以工作。我还包括我为数据库声明变量的位置。

 public class InspectionRecordsTableDBAdapter {
private static final String KEY_ROWID = "_id";
private static final String KEY_INSPECTION_ID = "inspection_id";
private static final String KEY_PARENT_NAME = "parent_name";
private static final String KEY_ITEM_NAME = "item_name";
private static final String KEY_COMMENT = "comment";
private static final String KEY_STATUS = "status";
private static final String DB_TABLE = "inspection_records";
private Context context;
private SignalSetDBHelper dbHelper;
private SQLiteDatabase db;
private SQLiteOpenHelper openHelper;

如果您需要更多代码,请告诉我。

4

1 回答 1

1
"item_name="+ item_name

应该

"item_name='"+ item_name + "'"

认为你错过了引号

于 2012-04-11T21:46:06.540 回答