"select * from health_advice where adviceTime between datetime(history,'localtime') and datetime(history,'start of day','localtime','+1 month')" history是一个string型,记录的是时间信息。sqlite报错说没有这一列,那就是sqlite把它当成了表中的某一列,那这个地方应该如何来使用这个变量呢
难道你的sql语句拼的不对? String str_sql = "select * from health_advice where adviceTime between datetime('" + history + "','localtime') and datetime('" + history + "','start of day','localtime','+1 month')";
String str_sql = "select * from health_advice where adviceTime between datetime(" + history + ",'localtime') and datetime(" + history + ",'start of day','localtime','+1 month')";
这样语法不对。我传的时间是"2013-05-05 00:00:00"它报错误06-24 11:38:55.054: E/AndroidRuntime(10406): Caused by: android.database.sqlite.SQLiteException: near "00": syntax error: , while compiling: select * from health_advice where adviceTime between datetime(2013-05-05 00:00:00,'localtime') and datetime(2013-05-05 00:00:00,'start of month','localtime','+1 month')
String sql = "select * from health_advice where adviceTime between datetime('2013-05-01 00:00:00','localtime') and datetime('2013-05-01 00:00:00','start of month','localtime','+1 month')";我这样就能查到
晕死了,搞的头大了 String historyA = "2013-05-01 00:00:00"; String sql = "select * from health_advice where adviceTime between datetime('" + historyA + "','localtime') and datetime('" + historyA + "','start of month','localtime','+1 month')"; 看看以上代码结果正常不?
String str_sql = "select * from health_advice where adviceTime between datetime('"
+ history
+ "','localtime') and datetime('"
+ history
+ "','start of day','localtime','+1 month')";
那你把我上面的history上面的''去了试试
+ history
+ ",'localtime') and datetime("
+ history
+ ",'start of day','localtime','+1 month')";
这样语法不对。我传的时间是"2013-05-05 00:00:00"它报错误06-24 11:38:55.054: E/AndroidRuntime(10406): Caused by: android.database.sqlite.SQLiteException: near "00": syntax error: , while compiling: select * from health_advice where adviceTime between datetime(2013-05-05 00:00:00,'localtime') and datetime(2013-05-05 00:00:00,'start of month','localtime','+1 month')
这个应该对的啊,区别就是''和"",如果不行你把'换成"",记得转义
这个应该对的啊,区别就是''和"",如果不行你把'换成"",记得转义
郁闷了,还是不行
这个应该对的啊,区别就是''和"",如果不行你把'换成"",记得转义
郁闷了,还是不行
其实很简单的,你在sqlite里面先执行sql语句,如果正确的话,你把他封闭成java语句就行了.
String historyA = "2013-05-01 00:00:00";
String sql = "select * from health_advice where adviceTime between datetime('" + historyA + "','localtime') and datetime('" + historyA + "','start of month','localtime','+1 month')";
看看以上代码结果正常不?