解决:sql server 中date类型,检索出该类型发现日期被减少了两天

遇到的问题:

以前在使用sqlserver的时候一般日期类型我会选择使用datetime类型,最近有个项目中使用了date类型,我在数据库插入的日期是1994-07-08结果检索出来的结果是1994-07-06,硬生生是少了两天。

先给出解决方案:

方案一:将数据库中date类型的字段改为datetime,就会正常显示时间;

方案二:自己下载JDBC Driver 4.0安装,该方案解释如下:

考虑下,你在java中使用jdbc方式访问数据库,是不是根本就没用引用过jdcb.jar包,也可以访问,一直以来我也没有深究这个问题,知道今天遇到这个问题,我就深究了一下。我的想法是在没有jdbc.jar包的情况下也可以访问数据库那么系统库中肯定有集成过jdbc,果然在JRS System library下的rt.jar中我就找到了集成的jdbc,如下图:


java.sql包下:


这就是为什么不自己导入jdbc.jar包也可以访问数据库的原因;

而微软官网是这样解释的:

Dear SQL Server developers and users:


Thank you for your ongoing support of the Microsoft JDBC Driver for SQL Server.  Some of you reported problems with dates when using JRE 1.7.

The Microsoft JDBC Driver for SQL Server currently supports JRE 1.5 & JRE 1.6, however we have made modifications to return correct date values regardless of the JRE version.This modification is available in the production version of the Microsoft JDBC Driver 4.0 for SQL Server.  The Microsoft JDBC Driver 4.0 for SQL Server is supported on JRE 1.5 and JRE 1.6, and support for JRE 1.7 is on our roadmap.

In addition, the driver modification is also available for SQL Server 2000 customers as a hotfix in the 3.0 version of our driver. Please review the hotfix article to determine if the fix is applicable to you and if so, click the link to download the hotfix (applicable for all platforms).


As always we are interested in your feedback. You may report bugs and issues via our forums. If you encounter Java bugs you may report those to Java.

Thank you,
Shamitha Reddy
Program Manager Microsoft JDBC Driver for SQL Server

核心解释我放大加红了,所以原因一目了然,说白的就是jdbc驱动(jre library中集成的也是)目前只支持JRE1.5和JRE1.6,目前微软已经提出的解决解决方案,就是下载JDBC Driver4.0 安装既可以解决这个问题。O(∩_∩)O哈哈~


  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值