Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android中使用子句查询SqlLite数据库_Android_Sqlite_Android Sqlite - Fatal编程技术网

在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
}