http://xiangai.taobao.com
http://shop148612228.taobao.com

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

该字段的值将表示为空

posted @ 2020-07-27 16:58  万事俱备就差个程序员  阅读(303)  评论(0编辑  收藏  举报

http://xiangai.taobao.com
http://shop148612228.taobao.com
如果您觉得对您有帮助.领个红包吧.谢谢.
支付宝红包
微信打赏 支付宝打赏