mysql datetime 类型与java.util.Date类型的值如何比较
怪我咯
怪我咯 2017-04-18 10:48:43
0
3
601

mysql datetime 类型与java.util.Date类型的值如何比较?

比如:

java.util.Date now = new Date();
select from table where create_time > now;
// create_time 是 date或者datetime或者timestamp类型

这样的sql字符串应该怎拼写?用什么mysql的函数?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(3)
小葫芦

The incoming date string is directly judged by equivalence

PHPzhong

Manual JDBC拼装SQL words:

select booking_time from me_orders where booking_time > '2016-11-19 09:29:11'; 

I tried it2016/11/19 09:29:1120161119092911It seems to work, but I still recommend that you use whatever form is in the table.

PHPzhong

You can convert Date to String and then use > to compare, as follows



String sql = "SELECT * FROM todo WHERE create_date > ? ";
PreparedStatement preStat = connection.prepareStatement(sql);
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
preStat.setString(1, sdf.format(date));
ResultSet rs = preStat.executeQuery();
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!