我正在查詢我的數據庫。當我使用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