0

我是安卓新手。我正在尝试从数据库(SQLite)中获取特定的单词。但是我无法使 where 子句起作用。我在哪里犯错?我的代码是:

    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();

}

我无法得到结果...

4

2 回答 2

1

打电话kayit.moveToFirst()前打电话kayit.getString(0)

于 2013-01-10T12:06:59.143 回答
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();
}
于 2013-01-10T12:10:37.007 回答