我的问题是,当我尝试从"中检索数据时,从TABLE_SEARCH_DETAILS中选择* WHERE KEY_SEARCH_PAIR +" '和searchpair'方法我得到Cursor null。该表具有所需的所有值。我已经使用db浏览器检查过了。代码如下。
String getCollectedDataQuery = "select * from " + TABLE_SEARCH_DETAILS + " WHERE " + KEY_SEARCH_PAIR + " = '" + searchPair+" '";
Cursor getCollectedCursor = groceryAppDatabase.rawQuery(getCollectedDataQuery, null);
if (getCollectedCursor==null){
Log.v("NULL","=="+getCollectedCursor);
}
但当我删除Query i中的部分获取数据时..任何人都知道我的"其中"部分在我的查询。
答案 0 :(得分:1)
rawQuery的第二个值应该是selectionArgs。试试这个:
String getCollectedDataQuery = "select * from " + TABLE_SEARCH_DETAILS + " WHERE " + KEY_SEARCH_PAIR + " = ?";
String[] queryArgs = new String[]{searchPair};
Cursor getCollectedCursor = groceryAppDatabase.rawQuery(getCollectedDataQuery, queryArgs);
答案 1 :(得分:0)
添加'在行尾
String getCollectedDataQuery = "select * from " + TABLE_SEARCH_DETAILS + " WHERE " + KEY_SEARCH_PAIR + " = '" + searchPair + "'";
Cursor getCollectedCursor = groceryAppDatabase.rawQuery(getCollectedDataQuery, null);
if (getCollectedCursor==null){
Log.v("NULL","=="+getCollectedCursor);
}