Choosing between java.util.Date or java.sql.Date

前端 未结 4 1564
-上瘾入骨i
-上瘾入骨i 2020-12-14 09:52

Should I use java.util.Date or java.sql.Date?

I have a VisualFox database and I have retrieved the entities with the IntelliJ Idea wizard using an appropiate jdbc ty

4条回答
  •  鱼传尺愫
    2020-12-14 10:06

    According to Java doc, it is suggested to use appropriate Date type as per underlying database. However, with Java 8, a rich set of classes under java.time package have been provided and it must be used if application is written with Java 8.

    The class javaxjava.sql.Date extends java.util.Date with minor changes for miliseconds container so that it can support the Database DATE type effectively. This, we can save the @Temporal annotation typing from entity class.

    However, java.util.Date could be used for better scalability in entire application so that it can be easily used to store time along with date.

提交回复
热议问题