在Android中使用子句查询SqlLite数据库
我在下面的查询中得到一个错误 错误是找不到类型字符串 我的问题出了什么问题在Android中使用子句查询SqlLite数据库,android,sqlite,android-sqlite,Android,Sqlite,Android Sqlite,我在下面的查询中得到一个错误 错误是找不到类型字符串 我的问题出了什么问题 String selectQuery = "SELECT * FROM " + TABLE_CONTACTS + " WHERE " + KEY_TYPE + " ='" + type + "'"; 我的原木猫 我的日志Cat 02-14 16:33:17.925:E/AndroidRuntime25839:java.lang.RuntimeException:无法启动activity ComponentInfo a
String selectQuery = "SELECT * FROM " + TABLE_CONTACTS + " WHERE " + KEY_TYPE + " ='" + type + "'";
我的原木猫
我的日志Cat 02-14 16:33:17.925:E/AndroidRuntime25839:java.lang.RuntimeException:无法启动activity ComponentInfo android.database.sqlite.SQLiteException:无此类列:类型:,编译时:从Mycontacts中选择*,其中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;
}
请再发一些代码!检查此链接。这对没有这样的列:type的问题没有帮助。
String QUERY = "SELECT * FROM Cart Where id=" + id";
cursor = data.selectQuery(QUERY);
int count = cursor.getCount();
if (count <= 0) {
/// insert
}else{
/// update
}