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 ww  .j a  va2  s .  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