2016-07-28 40 views
-1

我正在獲取並從數據庫表列中的值匹配,但它給android系統exception no such column nameandroid.database.sqlite.SQLiteException: no such column:speech但言語值列,但它給這個錯誤android.database.sqlite.SQLiteException:沒有這樣的列:caolumn價值

我使用此代碼

public List<TextJson> getDetailtospinner(String text_spinner1) { 
    SQLiteDatabase db = this.getReadableDatabase(); 
    List<TextJson> textList = null; 
    try{ 
     textList = new ArrayList<TextJson>(); 
     String[] columns = new String[]{KEY_ID,KEY_NAME}; 
     Cursor cursor = db.query(TABLE_TEXTS, columns, KEY_NAME + "=" + text_spinner1, null, null, null, null); 
     //Cursor cursor = db.rawQuery("SELECT * FROM "+TABLE_TEXTS + " WHERE " + KEY_CATE + " = " + text_spinner1 , null); 
     int rows = cursor.getCount(); 
     if (cursor != null) { 
      Log.e("0_0","0_0 1=>"); 
      for(int i=0;i<rows;i++) { 
       while (cursor.moveToNext()) { 
        TextJson txtlist = new TextJson(); 
        Log.e("0_0", ":(==>"); 
        txtlist.setId(cursor.getInt(0)); 
        txtlist.setText_status(cursor.getString(1)); 
        textList.add(txtlist); 
       } 
      } 
     } 
     db.close(); 
    }catch (Exception e){ 
     Log.e("error","is==> " +e); 
    } 
    return textList; 
} 

image

回答

3

括其中狀態值與'如果值不是整數。

Cursor cursor = db.rawQuery("SELECT * FROM "+TABLE_TEXTS + " WHERE " + KEY_CATE + " = '" + text_spinner1 +"'", null); 
+0

其給予例外'android.database.sqlite.SQLiteException:無法識別的標記: 「'」(代碼1):在編譯:SELECT * FROM文本WHERE txt_category = speech' – newdeveloper

+0

是現在它不顯示值。 ....在列表視圖中一切正常,但價值不是顯示 – newdeveloper

+0

@newdeveloper不,不這樣做,使用'rawQuery'的第二個參數,而不是 – pskink

相關問題