maja maja - 3 months ago 16
Java Question

Convert between LocalDate and sql.Date

What's the correct way to convert between

java.sql.Date
and
LocalDate
(Java8)?

Answer

The Java 8 version (and later) of java.sql.Date has built in support for LocalDate, including toLocalDate and valueOf(LocalDate).

To convert from LocalDate to java.sql.Date you can use

java.sql.Date.valueOf( localDate );

And to convert from java.sql.Date to LocalDate:

sqlDate.toLocalDate();