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


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


import java.util.Date;
//from  w  w  w  . java  2  s  . c  om
public class Main {

  public static void main(String[] args) {
    System.out.println(convertToSqlDate(new Date()));

  public static java.sql.Date convertToSqlDate(Date date) {
    return new java.sql.Date(date.getTime());

The code above generates the following result.