我是Android的新手。我试图从数据库(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();
}
我无法得到结果......
答案 0 :(得分:1)
在致电kayit.moveToFirst()
之前致电kayit.getString(0)
。
答案 1 :(得分: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();
}