我想在Android SQLite
中的两个日期之间检索数据我在SQLiteAdapter
类中使用了一个函数。我的功能是
public void history(String startdate,String enddate) {
Cursor mCursor = db.rawQuery("SELECT * FROM "+ KK_AIRLINEBOOK +
" WHERE " + KEY_Bookingdate +
" BETWEEN " + startdate + " AND " + enddate , null);
}
但是它无法正常显示AND
附近的语法错误
答案 0 :(得分:13)
放置文字
public void history(String startdate,String enddate) {
Cursor mCursor = db.rawQuery("SELECT * FROM "+ KK_AIRLINEBOOK +
" WHERE " + KEY_Bookingdate +
" BETWEEN '" + startdate + "' AND '" + enddate + "'", null);
}
但是如果你使用selectionArgs
会更好public void history(String startdate,String enddate) {
Cursor mCursor = db.rawQuery("SELECT * FROM "+ KK_AIRLINEBOOK +
" WHERE " + KEY_Bookingdate +
" BETWEEN ? AND ?", new String[]{startdate, enddate});
}