Differences between java.util.Date and java.sql.Date

0

I would like to know what is the difference between the objects java.util.Date and java.sql.Date , also if I am creating an application using Hibernate JPA which of these objects should I use to save my dates.

I must say that my application works well with both, as far as I have been able to prove, what I would like to know is if any of these objects has a feature that differentiates it from the other.

    
asked by nullptr 28.08.2017 в 22:43
source

2 answers

2

It's because of the information you get from each one:

  • java.util.Date = Represents an exact moment until the millisecond (2017 September 28 11:50:45)

  • java.sql.Date = Represents only one date (2017 September 28)

Generally you use java.sql.Date to form the PrepareStatement, since the BD would not accept the info provided by java.util.Date.

    
answered by 28.08.2017 в 22:57
0

according to the javadocumentacion

  • java.sql.Date in a wrapper class that covers the milliseconds, which are used by the JDBC to identify a date type in SQL.

  • java.sql.Date represents a date without informing time / time while java.util.Date represents both date and time.

  • sql.Date is a class inheritance of util.Date.

  • both classes mutate (hence they are very bad)

  • answered by 29.08.2017 в 11:19