本文介绍了查询"选取"返回sqlite的机器人没有匹配的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有查询问题选择
。当我尝试从 sqlite的,其中
条款的TextView
数据与数据库
这回没有匹配的数据。搭配
i have a problem with query select where
clause in sqlite
. When i try to match the data from textView
with database
it's return no matched data.
我的查询功能
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);
}
});
在第一code,这是为如果(add.equals())
条件,因此会显示安达tidak ADA tugas迪lokasi sekarang alaways运行...
请任何帮助。谢谢
In first code, it's alaways run to if(add.equals(""))
condition so it will show "Anda tidak ada tugas di lokasi sekarang"...Please any help. Thanks
推荐答案
使用如下:
Cursor cur = db.rawQuery("select * from task_table where alamat = '%" +
txtAlamat + "%'", null);
检查此有例如使用LIKE查询。和侯使用通配符在查询(缺少的格局字母)。
check this link there is example with LIKE Query. and hou use wildcards (missing letters in the pattern) in Query.
编辑:
Cursor cursor = db.rawQuery("select * from task_table where alamat = '%" +
txtAlamat + "%'", null);
if(cursor){
Toast.makeText(this, "no data", Toast.LENGTH_LONG).show();
}
if (cursor.moveToFirst()) {
do {
add = cur.getString(5);
if(!add.equalsIgnoreCase("")){
alarm = "Anda ada tugas di lokasi: " + add;
}else{
add = "Anda tidak ada tugas di lokasi sekarang";
alarm = "" + add;
}
} while (cursor.moveToNext());
}
这篇关于查询"选取"返回sqlite的机器人没有匹配的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!