在两个日期之间生成报告

时间:2014-01-26 19:17:05

标签: android

我想在以下两个日期之间检索数据是我的查询错误我需要它正确所以任何人都请帮助我 我也不需要rawquery我想要像下面那样做

public Cursor CstmRpot(String fd, String td) {
// TODO Auto-generated method stub
String[] columns = new String[] {EX_RowID,EX_Cattype, EX_Date, EX_Price, EX_Type };
Cursor c= ourdatabase.query(Food_TABLE, columns, EX_Date  + "= BETWEEN '"+ fd + "' 
 AND  '" + td + "'" , null, null, null, null);
if (c != null) {

       c.moveToFirst();

      }
return c;

} 

这是我的loggat我的查询只是想要改变我想但现在我很困惑我能用它做什么

01-27 00:22:24.827: E/AndroidRuntime(399): FATAL EXCEPTION: main
01-27 00:22:24.827: E/AndroidRuntime(399): java.lang.RuntimeException: Unable to start   
activity ComponentInfo{com.exmang/com.exmang.CstmrptShow}:  
android.database.sqlite.SQLiteException: near "'19-1-2014'": syntax error: , while  
compiling: SELECT _id, Ecattype, Ecdate, Ecprice, itype FROM FoodTable WHERE
EcdateBETWEEN '19-1-2014' AND '27-1-2014'
01-27 00:22:24.827: E/AndroidRuntime(399):  at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-27 00:22:24.827: E/AndroidRuntime(399):  at 
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-27 00:22:24.827: E/AndroidRuntime(399):  at 
android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-27 00:22:24.827: E/AndroidRuntime(399):  at 
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-27 00:22:24.827: E/AndroidRuntime(399):  at
android.os.Handler.dispatchMessage(Handler.java:99)
01-27 00:22:24.827: E/AndroidRuntime(399):  at android.os.Looper.loop(Looper.java:123)
01-27 00:22:24.827: E/AndroidRuntime(399):  at  
android.app.ActivityThread.main(ActivityThread.java:4627)
01-27 00:22:24.827: E/AndroidRuntime(399):  at  
java.lang.reflect.Method.invokeNative(Native Method)
01-27 00:22:24.827: E/AndroidRuntime(399):  at  
java.lang.reflect.Method.invoke(Method.java:521)
01-27 00:22:24.827: E/AndroidRuntime(399):  at  
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-27 00:22:24.827: E/AndroidRuntime(399):  at  
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-27 00:22:24.827: E/AndroidRuntime(399):  at dalvik.system.NativeStart.main(Native  
Method)
01-27 00:22:24.827: E/AndroidRuntime(399): Caused by:  
android.database.sqlite.SQLiteException: near "'19-1-2014'": syntax error: , while  
compiling: SELECT _id, Ecattype, Ecdate, Ecprice, itype FROM FoodTable WHERE  
EcdateBETWEEN '19-1-2014' AND '27-1-2014'
01-27 00:22:24.827: E/AndroidRuntime(399):  at  
android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
01-27 00:22:24.827: E/AndroidRuntime(399):  at    
android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
01-27 00:22:24.827: E/AndroidRuntime(399):  at    
android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
01-27 00:22:24.827: E/AndroidRuntime(399):  at android.database.sqlite.SQLiteProgram.  
<init>(SQLiteProgram.java:80)
01-27 00:22:24.827: E/AndroidRuntime(399):  at android.database.sqlite.SQLiteQuery.   
<init>(SQLiteQuery.java:46)
01-27 00:22:24.827: E/AndroidRuntime(399):  at   
android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
01-27 00:22:24.827: E/AndroidRuntime(399):  at   
android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
01-27 00:22:24.827: E/AndroidRuntime(399):  at   
android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1229)
01-27 00:22:24.827: E/AndroidRuntime(399):  at   
android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1184)
01-27 00:22:24.827: E/AndroidRuntime(399):  at 
android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1264)
01-27 00:22:24.827: E/AndroidRuntime(399):  at  
com.exmang.ExMgDB.CstmRpot(ExMgDB.java:112)
01-27 00:22:24.827: E/AndroidRuntime(399):  at   
com.exmang.CstmrptShow.displayListView(CstmrptShow.java:31)
01-27 00:22:24.827: E/AndroidRuntime(399):  at   
com.exmang.CstmrptShow.onCreate(CstmrptShow.java:23)
01-27 00:22:24.827: E/AndroidRuntime(399):  at   
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-27 00:22:24.827: E/AndroidRuntime(399):  at   
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-27 00:22:24.827: E/AndroidRuntime(399):  

1 个答案:

答案 0 :(得分:2)

如果最终转换为SQL,则正确的语法是:

WHERE SOME_DATE_COLUMN BETWEEN <Date1> AND <Date2>

所以你的问题(或你的一个问题)似乎就在这里。

EX_Date  + "= BETWEEN '"

删除=标志。