Java java.util.Date convert to java.sql.Date

Description

Java java.util.Date convert to java.sql.Date

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 a  v  a2  s .  c  om*/

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



PreviousNext

Related