我正在查询我的数据库。当我使用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;
}
如果我改变字符串ITEM_NAME为int inspectionItem它的工作原理。我还包括我为db声明了我的变量。
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;
如果您需要更多的代码,请告诉我。
ü应该用 “?”“ 谷歌查询selectionArgs两个 – Selvin 2012-04-11 21:43:53