有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

初始化java时出错。sql。日期

我正在JDeveloper中创建一个基于EJB的项目。我有一个在Oracle数据库中插入日期的功能,所以我想测试它是否正常工作。 我有一个测试方法,其中有以下声明:

java.sql.Date sDate = new java.sql.Date(System.currentTimeMillis());

在调试模式下,我转到变量,看到cdate的值为null,而fasttime字段填充了许多long(144…)类型。 [enter image description here]

我想知道为什么会出现不匹配。是虫子还是我弄错了?默认情况下,不是使用当前日期和时间创建的日期吗

有什么想法吗


共 (1) 个答案

  1. # 1 楼答案

    来自documentation

    public class Date extends Date A thin wrapper around a millisecond value that allows JDBC to identify this as an SQL DATE value. A milliseconds value represents the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT.

    To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with which the instance is associated.