2013-01-10 99 views
0

我是Android新手。我試圖從數據庫中獲取一個特定的詞(SQLite)。但是我不能讓where子句工作。我在哪裏犯錯? 我的代碼是:調用kayit.getString(0)Where子句不適用於Android SQLite

private String[] sutunlar = {"ingilizce","turkce"}; 

public void kelimeUret() { 

    SQLiteDatabase db = kelimeler.getReadableDatabase(); 

    Cursor kayit = db.query("kelimeler", sutunlar, "ingilizce='hello'", null, null, null, null); 

    String sonuc = kayit.getString(0); 

    Toast.makeText(getApplicationContext(), sonuc, Toast.LENGTH_SHORT).show(); 

} 

我不能得到的結果...

回答

1

呼叫kayit.moveToFirst()

+0

它的工作原理!非常感謝。 – halilkaya

0

你應該做這樣的事情

private String[] sutunlar = {"ingilizce","turkce"}; 
    public void kelimeUret() { 
    SQLiteDatabase db = kelimeler.getReadableDatabase(); 
    Cursor kayit = db.query("kelimeler", sutunlar, "ingilizce='hello'", null, null, null, null); 
    if (kayit.moveToFirst()) 
     { 
     String sonuc = kayit.getString(0); 
     Toast.makeText(getApplicationContext(), sonuc, Toast.LENGTH_SHORT).show(); 
     } 
    kayit.close(); 
}