Get the current date in java.sql.Date format

后端 未结 10 1978
傲寒
傲寒 2021-02-03 17:14

I need to add the current date into a prepared statement of a JDBC call. I need to add the date in a format like yyyy/MM/dd.

I\'ve try with

         


        
10条回答
  •  萌比男神i
    2021-02-03 17:36

    A java.util.Date is not a java.sql.Date. It's the other way around. A java.sql.Date is a java.util.Date.

    You'll need to convert it to a java.sql.Date by using the constructor that takes a long that a java.util.Date can supply.

    java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
    

提交回复
热议问题