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


I am trying to use a java.util.Date as input and then creating a query with it – so I need a java.sql.Date.

I was surprised to find that it couldn't do the conversion implicitly or explicitly – but I don't even know how I would do this, as the Java API is still fairly new to me.

Best Solution


public class MainClass {

  public static void main(String[] args) {
    java.util.Date utilDate = new java.util.Date();
    java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
    System.out.println("utilDate:" + utilDate);
    System.out.println("sqlDate:" + sqlDate);



explains it. The link is