2

我想在 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

4

1 回答 1

14

放置文字

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});        
}
于 2013-03-31T15:24:00.263 回答