0
我在下面的查詢中收到錯誤。在Android中查詢SqlLite數據庫使用子句
錯誤是它沒有找到類型字符串。
我的查詢出了什麼問題?
String selectQuery = "SELECT * FROM " + TABLE_CONTACTS + " WHERE " + KEY_TYPE + " ='" + type + "'";
我的日誌貓 我的日誌貓02-14 16:33:17.925:E/AndroidRuntime(25839):了java.lang.RuntimeException:無法啓動活動ComponentInfo android.database.sqlite.SQLiteException:無這樣的列:類型:,編譯時:SELECT * FROM Mycontacts其中type = '白名單'
完整查詢代碼
public List<Contacts> getAllphContacts(String type) {
List<Contacts> contactList = new ArrayList<Contacts>();
// Select All Query
//String selectQuery = "SELECT * FROM " + TABLE_CONTACTS +KEY_TYPE + "=?"; //*tried this also
String selectQuery = "SELECT * FROM " + TABLE_CONTACTS + " WHERE " + KEY_TYPE + " ="+ type; //***this also not working
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
Contacts contact = new Contacts();
contact.setphid(Integer.parseInt(cursor.getString(0)));
contact.setphname(cursor.getString(1));
contact.setphnumber(cursor.getString(2));
contact.settype(cursor.getString(3));//********For whiteList*********//
// Adding contact to list
contactList.add(contact);
} while (cursor.moveToNext());
}
cursor.close();
db.close();
// return contact list
return contactList;
}
發佈一些更多的代碼,請! –
選中此鏈接。 http://stackoverflow.com/questions/15594716/android-sqlite-query-where-and-where –