在SQL Server中发布日期提取 [英] Issue with a date extraction in SQL Server

查看:112
本文介绍了在SQL Server中发布日期提取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用SQL Server列出在表中注册的日期,但我的问题是我提取的所有日期与表中的日期相差2天。



例如,我在我的数据库中得到了2012-12-25,当我检索它并将其转换为Java.util.Date时,它变成了2012-12-23 ...



我在另一个表中的日期处理过程中工作正常。



我使用SQL Server 2008,Hibernate 3和Spring 3.

编辑:

该表的列数据类型是日期,我正在检索它使用hibernate所以这里是我的hibernate查询调用:

  public List< Holiday> retrieveAllHolidays(){
return(List< Holiday>)sessionFactory.getCurrentSession()。createQuery(from Holiday)
.list();
}

假期对象有两个属性:一个字符串和一个日期从数据库中检索后不正确)。

解决方案

该问题与JDBC驱动程序的JRE 7支持getDate()函数)。



有关更多信息,请参阅此文章: Microsoft JDBC驱动程序团队博客



再次感谢Martin Smith指出另一个问题!


I'm trying to list the dates registered in a table with SQL Server, but my problem is all the dates I'm extracting differs of 2 days with the dates in the table.

For example, I got 2012-12-25 in my database and when I retrieve it and cast it to a Java.util.Date, it becames 2012-12-23...

I've got processes on dates in another table which are working fine.

I'm using SQL Server 2008, Hibernate 3 and Spring 3.

Edit:

The column data type for the table is date, I'm retrieving it using hibernate so here is my hibernate query call:

public List<Holiday> retrieveAllHolidays() {
    return (List<Holiday>) sessionFactory.getCurrentSession().createQuery("from Holiday")
    .list();
}

The holiday object got two attributes: a String and a Date (this one is incorrect after retrieving from database).

解决方案

The problem was linked with the JRE 7 support of the JDBC Driver (a problem with the getDate() function).

See this post for more informations: Microsoft JDBC driver team blog

Thanks again Martin smith for pointing to that other issue!

这篇关于在SQL Server中发布日期提取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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