如何在一段时间内从mysql获取数据(使用TimeStamp)?

时间:2018-04-04 02:27:37

标签: mysql jdbc timestamp

我是新手使用“jdbc”,我有一些问题。我使用“where”在十分钟内选择mysql中的数据。例如,如果时间是2018-4-4 10:11,那么我想要2018-4-4 10:01和2018-4-4 10:11之间的数据。有一个名为“cTime”的列,其类型为TimeStamp 这是我的代码:

Date date = new Date();
Timestamp nousedate = new Timestamp(date.getTime()-10*60*1000);
"select app.appkey from " + getClassName() +" app where app.cTime >" +nousedate +  " group by app.appkey”

它没有用。如果我将代码更改为:

"select app.appkey from " + getClassName() +" app 
where app.cTime > 2018-4-4 10:01’’ 
group by app.appkey”

然后它起作用。
我不知道出了什么问题。我使用了很多方法,但它们没有用。所以我想得到一些帮助。 提前谢谢。

0 个答案:

没有答案