Java date to sql date

蓝咒 提交于 2019-11-28 14:41:36

Use

prs.setDate( 1, new java.sql.Date( date.getTime() ) );

The types java.sql.Date and java.sql.Timestamp are suppoed to be used to set date and timestamp fields, respectively. Read their documentation for the differences between them and between them and java.util.Date.

You usually get a java date (java.util.Date) from the user. You convert it to milliseconds since the epoch using getTime(), and then convert back to a java.sql.Date or java.sql.Timestamp as I have shown.

use this it can help

  static  java.sql.Timestamp getSqlDate(Date date) {    
        java.util.Date javaDate = date;
        long javaTime = javaDate.getTime();
        java.sql.Timestamp sqlTimestamp = new java.sql.Timestamp(javaTime);
        return sqlTimestamp;
 }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!