将值传递给DB Helper

时间:2018-02-11 18:34:58

标签: android sqlite

我将值传递给DB Helper进行查询,我有2个错误。

查询中的一个

DB助手:

public Cursor opis(final String sid){
    SQLiteDatabase db = this.getWritableDatabase();
    final String ID = sid;
    Cursor rezultat = db.rawQuery("Select opis from tablica where id = ? LIMIT 1" , new String[] {ID});
    return rezultat;
}

错误在问号上: enter image description here

第二个错误出现在我的MainActivity中:

private void prikaz() {
    final ListView listView = (ListView) findViewById(R.id.idListView);
    ArrayList<String> theList = new ArrayList<>();
    Cursor data = myDb.opis();
    if(data.getCount() == 0){
        Toast.makeText(this, "No data!",Toast.LENGTH_LONG).show();
    }
    else
    {
        while(data.moveToNext()){
            String opis = data.getString(0);

        }

    }
}

错误:
enter image description here

1 个答案:

答案 0 :(得分:-1)

第一次使用错误

Cursor rezultat = db.rawQuery("Select opis from tablica where id = '"+yourvalue+"' LIMIT 1" , new String[] {ID});

对于secound,您应该将String值传递给方法opis()