针对listview的Android过滤器sqlite结果

时间:2014-12-04 20:53:26

标签: java android sqlite filtering

您好我的查询字符串的语法有问题,用于过滤在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;
}

我已经尝试了很多解决方案,但似乎没有一个对我有用,任何建议都会很棒..谢谢

1 个答案:

答案 0 :(得分:0)

当您在String子句中使用where类型时,它应该是单引号。

where title like '%" + inputText +"'"