【发布时间】:2014-12-12 18:14:32
【问题描述】:
"CREATE TABLE IF NOT EXISTS part_prices_by_context_run_at ( "
+ "context text, run_at timestamp,feed_type text, "
+ "part text, price double, "
+ "PRIMARY KEY ((context, run_at), part))"
"INSERT INTO part_prices_by_context_run_at (context,run_at,feed_type,part,price)" +
" VALUES ('US|en-us|consumer','2014-12-10 01:00:00','partial','MXFL1/A',236.29)"
String oldstring = "2014-12-10 01:00:00";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
date = format.parse(oldstring);
PartPricesByContextRunAtKeyImpl key = new PartPricesByContextRunAtKeyImpl();
key.setContext("US|en-us|consumer");
key.setRunAt(date);
Collection<PartPricesByContextRunAt> partPrices = dao.retrievePartPrices(key);
Assert.assertNotNull(partPrices);
断言失败,因为 partPrices 始终为 null 并抛出错误
错误:无法将“Wed Dec 10 01:00:00 PST 2014”强制转换为格式化日期(长)
看起来在查询时,日期变为“Wed Dec 10 01:00:00 PST 2014”,但插入的格式不同,即“2014-12-10 01:00:00”
【问题讨论】: