TIMESTAMP使用遇到得麻烦
mysql按日期查询报空,怎么查看日志发现是14:36:01.709(Timestamp), 参数出了问题
2018-04-17 14:36:16,887 [http-nio-8080-exec-5] DEBUG [cn.jbit.dao.OrderDao.addOrder] - ==> Preparing: INSERT INTO `order`(`uId`,`byTime`,`totalPrice`,`paymenttype`,`paymentState`) VALUES(?,?,?,?,?)
2018-04-17 14:36:16,899 [http-nio-8080-exec-5] DEBUG [cn.jbit.dao.OrderDao.addOrder] - ==> Parameters: 2(Integer), 2018-04-17 14:36:01.709(Timestamp), 89.4(Double), 1(Integer), 1(Integer)
2018-04-17 14:36:16,947 [http-nio-8080-exec-5] DEBUG [cn.jbit.dao.OrderDao.addOrder] - <== Updates: 1
2018-04-17 14:36:58,135 [http-nio-8080-exec-5] DEBUG [cn.jbit.dao.OrderDao.searchByInfo] - ==> Preparing: SELECT * FROM `order` WHERE `uId`=? AND `byTime`=? AND `totalPrice`=?
2018-04-17 14:36:58,139 [http-nio-8080-exec-5] DEBUG [cn.jbit.dao.OrderDao.searchByInfo] - ==> Parameters: 2(Integer), 2018-04-17 14:36:01.709(Timestamp), 89.4(Double)
2018-04-17 14:36:58,154 [http-nio-8080-exec-5] DEBUG [cn.jbit.dao.OrderDao.searchByInfo] - <== Total: 0
数据库数据如下,只保存到了秒
无奈用了一下转换,以后会研究如何保存到毫秒
DateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date= dateFormat2.format(order.getByTime());
try {
Date myDate2 =dateFormat2.parse(date);
order.setByTime(myDate2);
} catch (ParseException e) {
e.printStackTrace();
}