Java Data Type How to - Convert LocalDate to java.sql.Date








Question

We would like to know how to convert LocalDate to java.sql.Date.

Answer

import java.sql.Date;
import java.time.LocalDate;
//from w w w.j a va2  s .  c om
public class Main {

  public static void main(String[] args) {
    System.out.println(convertToDatabaseColumn(LocalDate.now()));
  }

  public static Date convertToDatabaseColumn(LocalDate localDate) {
    return Date.valueOf(localDate);
  }

}

The code above generates the following result.