zoukankan      html  css  js  c++  java
  • 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

    该字段的值将表示为空

  • 相关阅读:
    Java实现 LeetCode 167 两数之和 II
    Java实现 LeetCode 1227 飞机座位分配概率
    Java实现 LeetCode 1227 飞机座位分配概率
    Java实现 LeetCode 1227 飞机座位分配概率
    Java实现 LeetCode 166 分数到小数
    QueryPerformanceFrequency 和 QueryPerformanceCounter用法
    VC中利用多线程技术实现线程之间的通信
    C++著名类库和C++标准库介绍
    CRectTracker类的使用--橡皮筋窗口
    备份3个判断指针是否有效的函数,以备不时之需
  • 原文地址:https://www.cnblogs.com/suizhikuo/p/13386327.html
Copyright © 2011-2022 走看看