Value '0000-00-00' can not be represented as java.sql.Date

后端 未结 6 1217
名媛妹妹
名媛妹妹 2020-12-05 08:43

I\'m working on some project which needs to extract data from DB and I use Spring MVC to build model from DB for selecting data.

Here is the problem with my

6条回答
  •  没有蜡笔的小新
    2020-12-05 09:23

    In MySql '0000-00-00' is considered a valid date, but it can't be repesented as java.sql.Date.

    You could use a query that returns NULL in case date is '0000-00-00', or the actual value otherwise:

    SELECT
      CASE WHEN `date`!='0000-00-00' THEN `date` END new_date
    FROM
      yourtable
    

    or you can add to your datasource connection string this:

    zeroDateTimeBehavior=convertToNull
    

    and dates as '0000-00-00' will be automatically converted to NULL.

提交回复
热议问题