我的查询select where
子句有问题sqlite
。当我尝试将数据textView
与之匹配时,database
它不会返回匹配的数据。
我的查询功能
public void cekPosisi(String txtAlamat) {
String add = "";
String alarm = "";
Cursor cur = db.rawQuery("select * from task_table where alamat = '" +
txtAlamat + "'", null);
if(cur.moveToFirst()) {
add = cur.getString(5);
alarm = "Anda ada tugas di lokasi: " + add;
for (; !cur.isAfterLast(); cur.moveToNext()) {
add = cur.getString(5);
alarm = "Anda ada tugas di lokasi: " + add;
}
}
if(add.equals("")) {
add = "Anda tidak ada tugas di lokasi sekarang";
alarm = "" + add;
}
Toast.makeText(this, alarm, Toast.LENGTH_LONG).show();
}
实施于
//cek tugas
this.cariTugas.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
txtAddr = teksAlamat.getText().toString();
Log.d("alamat textView", txtAddr);
cekPosisi(txtAddr);
}
});
在第一个代码中,它总是运行到if(add.equals(""))
条件,所以它会显示“Anda tidak ada tugas di lokasi sekarang”......请帮助。谢谢