Reputation: 467
I'm new in Android. I'm trying to get a specific word from database (SQLite). But I couldn't make where clause work. Where am I making mistake? My code is it:
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();
}
I can not get a result...
Upvotes: 0
Views: 266
Reputation: 15424
You should do something like this
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();
}
Upvotes: 0
Reputation: 28767
Call kayit.moveToFirst()
before calling kayit.getString(0)
.
Upvotes: 1