• java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp是因为时间字段里有'0000-00-00 00:00:00‘这种格式的日期导致的


    Exception in thread "main" org.dbunit.dataset.DataSetException: java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
        at org.dbunit.database.ForwardOnlyResultSetTable.getValue(ForwardOnlyResultSetTable.java:108)
        at org.dbunit.dataset.DefaultTable.addTableRows(DefaultTable.java:139)
        at org.dbunit.database.CachedResultSetTable.<init>(CachedResultSetTable.java:69)
        at org.dbunit.database.CachedResultSetTableFactory.createTable(CachedResultSetTableFactory.java:52)
        at org.dbunit.database.QueryTableIterator.getTable(QueryTableIterator.java:151)
        at org.dbunit.dataset.stream.DataSetProducerAdapter.produce(DataSetProducerAdapter.java:83)
        at org.dbunit.dataset.xml.FlatXmlWriter.write(FlatXmlWriter.java:124)
        at org.dbunit.dataset.xml.FlatXmlDataSet.write(FlatXmlDataSet.java:378)
        at dbunit.Test.main(Test.java:27)
    Caused by: java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
        at com.mysql.jdbc.ResultSetRow.getTimestampFast(ResultSetRow.java:1102)
        at com.mysql.jdbc.ByteArrayRow.getTimestampFast(ByteArrayRow.java:127)
        at com.mysql.jdbc.ResultSetImpl.getTimestampInternal(ResultSetImpl.java:6592)
        at com.mysql.jdbc.ResultSetImpl.getTimestamp(ResultSetImpl.java:6192)
        at org.dbunit.dataset.datatype.TimestampDataType.getSqlValue(TimestampDataType.java:161)
        at org.dbunit.database.ForwardOnlyResultSetTable.getValue(ForwardOnlyResultSetTable.java:104)
        ... 8 more

    java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp是因为时间字段里有'0000-00-00 00:00:00‘这种格式的日期导致的

    解决方法,把这种日期换成标准的日期格式,年月日不能用0表示

    或者在mysql连接的时候添加如下字符串

    jdbc:mysql://localhost/mydb?zeroDateTimeBehavior=convertToNull

    该字段的值将表示为空

  • 相关阅读:
    面试小结
    Everything工具使用
    记 · 工作一周年
    贝叶斯算法原理分析
    MySQL与Oracle主键Query性能测试结果
    K-meams文本聚类算法C++实现
    OPTICS光学算法
    页面添加内容后弹出框与跳转页面
    Webgrid参数格式
    页面2级分类
  • 原文地址:https://www.cnblogs.com/suizhikuo/p/13386327.html
Copyright © 2020-2023  润新知