• Mysql 时间格式默认空串 '0000-00-00 00:00:00' select抛出异常的解决方法


    Mysql 时间格式默认插入值为空时,会以'0000-00-00 00:00:00'填充,这时如果select时会抛出SQLExecption如下:

    java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp

    解决方法如下:

    方法一:jdbc的url加入zeroDateTimeBehavior参数: 

    datasource.url=jdbc:mysql://localhost:3306/testdb?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true 

    zeroDateTimeBehavior=round是为了指定MySql中的DateTime字段默认值查询时的处理方式;默认是抛出异常,

    (摘自:http://www.blogjava.net/hilor/articles/164814.html)

    方法二:select 语句中做如下处理:

    SELECT ID, IF(createDate='0000-00-00 00:00:00','null',createDate)createDate FROM T_DateTest;

    这里将createDate格式转换为”null“展示,不再抛出SQLException。

  • 相关阅读:
    有向无环图
    2016
    Permutation Descent Counts(递推)
    Rikka with Subset
    hihoCoder 1549 或运算和
    Young Maids
    1925: [Sdoi2010]地精部落
    Problem H. Hotel in Ves Lagos
    改变presentModalView大小
    no such file to load -- bundler/setup
  • 原文地址:https://www.cnblogs.com/hunterCecil/p/5543732.html
Copyright © 2020-2023  润新知