Java - Write code to convert to java.util.Date to java.sql.Date

Requirements

Write code to convert to java.util.Date to java.sql.Date

Demo

import java.util.Date;

public class Main {
  public static void main(String[] argv) {
    Date date = new Date();
    System.out.println(toSqlDate(date));
  }//from   w w w . j  av a 2s .  c o m

  public static java.sql.Date toSqlDate(Date date) {
    if (date != null) {
      return new java.sql.Date(date.getTime());
    } else {
      return null;
    }
  }
}

Related Exercise