【发布时间】:2014-02-14 20:17:26
【问题描述】:
我在以下查询中遇到错误。
错误是它没有找到类型字符串。
我的查询有什么问题?
String selectQuery = "SELECT * FROM " + TABLE_CONTACTS + " WHERE " + KEY_TYPE + " ='" + type + "'";
我的原木猫 My Log Cat 02-14 16:33:17.925: E/AndroidRuntime(25839): java.lang.RuntimeException: Unable to start activity ComponentInfo android.database.sqlite.SQLiteException: no such column: type: , while compile: SELECT * FROM Mycontacts WHERE type ='whitelist'
完整的查询代码
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;
}
【问题讨论】:
-
请贴更多代码!
标签: android sqlite android-sqlite