Get the current date in java.sql.Date format

后端 未结 10 2029
傲寒
傲寒 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条回答
  •  感动是毒
    2021-02-03 17:50

    all you have to do is this

        Calendar currenttime = Calendar.getInstance();               //creates the Calendar object of the current time
        Date sqldate = new Date((currenttime.getTime()).getTime());  //creates the sql Date of the above created object
        pstm.setDate(6, (java.sql.Date) date);              //assign it to the prepared statement (pstm in this case)
    

提交回复
热议问题