2
我有一個名爲Order的表,由3列(id,date,price)組成。我試圖檢索date >= startdate AND date <= endDate
的所有數據。列date
的日期是在這種格式保存爲TEXT
:"MM-dd-yyyy HH:mm:ss"
(10-27-2013 12:12:43
)根據日期從MySQL數據庫獲取數據
我曾嘗試下面的SQL語句:
Cursor cursor = cr.query(PizzeriaContentProvider.CONTENT_URI_ORDER, null, PizzeriaDatabase.CELL_ORDER_DATE + " >= DATETIME ("+ startDate + ") AND " +
PizzeriaDatabase.CELL_ORDER_DATE + " <= DATETIME(" + endDate + ")", null, null);
Cursor cursor = cr.query(PizzeriaContentProvider.CONTENT_URI_ORDER, null, PizzeriaDatabase.CELL_ORDER_DATE + " between (" + startDate + " AND " + endDate + ")", null, null);
但他們都拋出同樣的異常:
java.lang.RuntimeException: Unable to start activity ComponentInfo{cz.vongrad.pizzeria/presentationLayer.ViewOrder}:
android.database.sqlite.SQLiteException: near "14": syntax error: ,
while compiling: SELECT * FROM orders WHERE (date >= DATETIME(10-27-2013 14:01:53) AND date <= DATETIME(10-27-2013 14:01:53))
所以我想我比較錯誤的格式日期?
謝謝,我不知道它必須是引號之間。我會標記你在5分鐘內接受答案,它不允許我現在做... – Husky
@赫斯基:當然...不是問題 –