使用时间格式选择日期查询不能与JDBCTemplate和util.Date一起使用 [英] Select date query with time format is not working with JDBCTemplate and util.Date

查看:2509
本文介绍了使用时间格式选择日期查询不能与JDBCTemplate和util.Date一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring JDBCTemplate来连接数据库。当我使用以下查询选择数据库日期



从to_date(valid_to,'DD-MM-YYYY HH24:MI:SS')中选择组合



输出是,31-12-99 23:59:59。



但是,当我像下面的JDBCTemplate一样使用它时,

 日期d = jdbcTemplate.queryForObject(select to_date valid_to,'DD-MM-YY HH24:MI:SS')从组合,Date.class); 

outpt是2099-12-31 00:00:00.0。



时间不正确。我也需要在Date类中同一时间。怎么搞定

解决方案

感谢您的回复。我找到了一种方式来花时间。

  String dateString = jdbcTemplate.queryForObject(select to_char(valis_to,'DD-MM-YYYY HH24:MI:SS')从组合,String.class); 
Date date = sdf.parse(dateString);


I am using Spring JDBCTemplate to conneect DB. When I am selecting date in DB using below query

select to_date(valid_to,'DD-MM-YYYY HH24:MI:SS') from composition

output is, 31-12-99 23:59:59.

But, when I am using the same with JDBCTemplate like below,

Date d = jdbcTemplate.queryForObject("select to_date(valid_to,'DD-MM-YY HH24:MI:SS') from composition",Date.class);

outpt is 2099-12-31 00:00:00.0.

Time is not correct. I also need the same time in Date class. How to get that?

解决方案

Thanks for all your response. I found a way to take the time.

String dateString = jdbcTemplate.queryForObject("select to_char(valis_to, 'DD-MM-YYYY HH24:MI:SS') from composition",String.class);
Date date = sdf.parse(dateString);

这篇关于使用时间格式选择日期查询不能与JDBCTemplate和util.Date一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆