【问题标题】:Quering SqlLite database using clause in Android在Android中使用子句查询Sqlite数据库
【发布时间】: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


【解决方案1】:
    String QUERY = "SELECT * FROM Cart Where id=" + id";
cursor = data.selectQuery(QUERY);
int count = cursor.getCount();

if (count <= 0) {
/// insert
}else{

/// update
}

【讨论】:

  • 这无助于解决问题no such column: type
猜你喜欢
  • 2014-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多