我有类似的东西。我想查询日期和用户名是否与提供的字符串(参数)匹配并返回结果。我尝试了下面的语法,但它给了我错误。谢谢你的帮助
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);
}
答案 0 :(得分:1)
您需要使用AND加入您的条件:
Cursor c = ourDataBase.query(DATABASE_TABLE_EVENTS, columns, KEY_DATE
+ " like ? and " + KEY_REF + " like ?", new String[] {date,username}, null, null, null);
//-----------------^^^