我将值传递给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;
}
第二个错误出现在我的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);
}
}
}
答案 0 :(得分:-1)
第一次使用错误
Cursor rezultat = db.rawQuery("Select opis from tablica where id = '"+yourvalue+"' LIMIT 1" , new String[] {ID});
对于secound,您应该将String值传递给方法opis()