SQlite android查询中的LIKE语句错误
我对sqlite android中的LIKE语句有一个问题。我用了一个小时来计算,但我无法得到错误部分。有人知道我的错在哪里吗SQlite android查询中的LIKE语句错误,android,sqlite,Android,Sqlite,我对sqlite android中的LIKE语句有一个问题。我用了一个小时来计算,但我无法得到错误部分。有人知道我的错在哪里吗 public Cursor getSearch(String id) { String[] args = { id }; return (database.rawQuery("SELECT " + SQLiteHelper.product_id + " as _id,"
public Cursor getSearch(String id) {
String[] args = { id };
return (database.rawQuery("SELECT " + SQLiteHelper.product_id
+ " as _id,"
+ SQLiteHelper.productName + " ," +SQLiteHelper.productDesp
+ "," + SQLiteHelper.productQtty + ","
+SQLiteHelper.product_CategoryF+" FROM "
+ SQLiteHelper.productTable+" WHERE "
+ SQLiteHelper.productName +" LIKE 'id%'",null));
}
错误消息
bind or column index out of range: handle 0x5e3ec0
有人知道我的错在哪里吗
public Cursor getSearch(String id) {
String[] args = { id };
return (database.rawQuery("SELECT " + SQLiteHelper.product_id
+ " as _id,"
+ SQLiteHelper.productName + " ," +SQLiteHelper.productDesp
+ "," + SQLiteHelper.productQtty + ","
+SQLiteHelper.product_CategoryF+" FROM "
+ SQLiteHelper.productTable+" WHERE "
+ SQLiteHelper.productName +" LIKE 'id%'",null));
}
解决方案
return (database.rawQuery("SELECT " + SQLiteHelper.product_id
+ " as _id,"
+ SQLiteHelper.productName + " ," +SQLiteHelper.productDesp
+ "," + SQLiteHelper.productQtty + ","
+SQLiteHelper.product_CategoryF+" FROM "
+ SQLiteHelper.productTable+" WHERE "
+ SQLiteHelper.productName +" LIKE '"+id+"%'",null));
您不需要像这样形成SQL
rawQuery
使绑定参数变得非常容易
rawQuery("SELECT ? as _id, ?, ?, ?, ? FROM ? WHERE ? LIKE 'id%'", new String[] {SQLiteHelper.product_id, SQLiteHelper.productName, SQLiteHelper.productDesp, SQLiteHelper.productQtty, SQLiteHelper.product_CategoryF, SQLiteHelper.productTable, SQLiteHelper.productName});
就您的代码而言,请注意,,“+
在您的分类行上应该是+”,
检查以下语法:-“+SQLiteHelper.product_CategoryF+”from”。删除此“”。在like中,它应该是这样的“like'”+id+“%”,null。试试这个好的,谢谢你的帮助…我知道我的错误。。