首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

sqlite查询,datetime有关问题

2013-07-04 
sqlite查询,datetime问题select * from health_advice where adviceTime between datetime(history,loca

sqlite查询,datetime问题


"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')";

[解决办法]
引用:
Quote: 引用:

难道你的sql语句拼的不对?
String str_sql = "select * from health_advice where adviceTime between datetime('"
+ history
+ "','localtime') and datetime('"
+ history
+ "','start of day','localtime','+1 month')";

按照你这个我没找到记录,但是我把history换成字符串常量"2013-05-01 00:00:00"就可以查到数据

那你把我上面的history上面的''去了试试
[解决办法]
String str_sql = "select * from health_advice where adviceTime between datetime("
+ history
+ ",'localtime') and datetime("
+ history
+ ",'start of day','localtime','+1 month')";

[解决办法]
引用:
Quote: 引用:

难道你的sql语句拼的不对?
String str_sql = "select * from health_advice where adviceTime between datetime('"
+ history
+ "','localtime') and datetime('"
+ history
+ "','start of day','localtime','+1 month')";


按照你这个我没找到记录,但是我把history换成字符串常量"2013-05-01 00:00:00"就可以查到数据

这个应该对的啊,区别就是''和"",如果不行你把'换成"",记得转义
[解决办法]
引用:
Quote: 引用:

Quote: 引用:

Quote: 引用:

难道你的sql语句拼的不对?
String str_sql = "select * from health_advice where adviceTime between datetime('"
+ history
+ "','localtime') and datetime('"
+ history
+ "','start of day','localtime','+1 month')";

按照你这个我没找到记录,但是我把history换成字符串常量"2013-05-01 00:00:00"就可以查到数据

这个应该对的啊,区别就是''和"",如果不行你把'换成"",记得转义

郁闷了,还是不行

其实很简单的,你在sqlite里面先执行sql语句,如果正确的话,你把他封闭成java语句就行了.
[解决办法]
引用:
Quote: 引用:

 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')";


看看以上代码结果正常不?


热点排行