Data truncation: Incorrect datetime value: '' for column 'create_time' at row 1 问题

 

 

 

org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [insert into orders values(?,?,?,?,?,?,?,?,?,?,?)]; Data truncation: Incorrect datetime value: '' for column 'create_time' at row 1; nested exception is com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '' for column 'create_time' at row 1

 

Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '' for column 'create_time' at row 1

 

源代码:

        order.setCreateTime(new Date());

数据库类型:

 

 

改进后:

        //取当前时间
        Date nowdate=new Date();
        //转换时间格式
        SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        order.setCreateTime(Timestamp.valueOf(simpleDate.format(nowdate)));

 

参考了他人的解决方法,附上链接:https://www.baidu.com/link?url=BDZ3hLZ7U-uUztwZA_lqMqZUO14WFpYIAIHkhonXbfkDk97c-n3_e7fSl-4mtvvmhiGtT3jD2MmNOVTIC9rM5esYR9IWGsYb34l3fDHC9fG&wd=&eqid=ebcd69550013f1ed000000065f0fb8bb

posted @ 2020-07-16 10:28  cts1234  阅读(10672)  评论(0编辑  收藏  举报