1

我有这样的东西。我想查询日期和用户名是否与提供的字符串(参数)匹配并返回结果。我尝试了下面的语法,但它给了我错误。谢谢您的帮助

    public String getOneDayEvents(String date, String username) {
    String[] columns = new String[] { KEY_TITLE, KEY_DESCRIPTION,
            KEY_START_TIME, KEY_END_TIME };
    Cursor c = ourDataBase.query(DATABASE_TABLE_EVENTS, columns, KEY_DATE
            + " like ? " + KEY_REF + " like ?", new String[] {date,username}, null, null, null);
    String result = "";

    int iTitle = c.getColumnIndex(KEY_TITLE);
    int iDesc = c.getColumnIndex(KEY_DESCRIPTION);
    int istartTime = c.getColumnIndex(KEY_START_TIME);
    int iendTime = c.getColumnIndex(KEY_END_TIME);

}

4

1 回答 1

1

您需要使用 AND 加入您的条件:

Cursor c = ourDataBase.query(DATABASE_TABLE_EVENTS, columns, KEY_DATE
        + " like ? and " + KEY_REF + " like ?", new String[] {date,username}, null, null, null);
//-----------------^^^
于 2012-11-23T06:41:51.857 回答