您好我的查询字符串的语法有问题,用于过滤在Android上显示sqlite结果的列表视图的结果。
public Cursor searchByInputText(String inputText) throws SQLException {
String query = "SELECT _id as _id," +" title" + " from " + TABLE_NAME + " where " + "title" + " LIKE '" + inputText + "';";
//String query = "SELECT _id as _id," +" title" + " from " + TABLE_NAME + " where " + "title" + " LIKE '" + inputText + "';";
//String query = "SELECT _id from " + TABLE_NAME + " WHERE title="+inputText;
Cursor mCursor = database.rawQuery("SELECT _id as _id, title from "+TABLE_NAME +" where title like " + inputText,null);
if (mCursor != null) {
mCursor.moveToFirst();
System.out.println(query);
}
return mCursor;
}
我已经尝试了很多解决方案,但似乎没有一个对我有用,任何建议都会很棒..谢谢
答案 0 :(得分:0)
当您在String
子句中使用where
类型时,它应该是单引号。
where title like '%" + inputText +"'"