java – 无法将值从列XX转换为“2012-04-05 10:20:00”到TIMESTAMP

前端之家收集整理的这篇文章主要介绍了java – 无法将值从列XX转换为“2012-04-05 10:20:00”到TIMESTAMP前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

当JDBC尝试将MySQL(5.1.51)中的有效日期时间转换为java.sql.timestamp时,将抛出java.sql.sqlException.一个例子是:

java.sql.sqlException: Cannot convert value '2012-04-05 10:20:00' from column 40 to TIMESTAMP

这是第一次

Versions:
MysqL: 5.1.51
J/Connector: 5.1.19
Column Definition:  DATETIME
Java Type:   java.sql.Timestamp

堆栈跟踪:

Cannot convert value '2012-04-05 10:20:00' from column 40 to TIMESTAMP.
    at com.MysqL.jdbc.sqlError.createsqlException(sqlError.java:1073)
    at com.MysqL.jdbc.sqlError.createsqlException(sqlError.java:987)
    at com.MysqL.jdbc.sqlError.createsqlException(sqlError.java:982)
    at com.MysqL.jdbc.sqlError.createsqlException(sqlError.java:927)
    at com.MysqL.jdbc.ResultSetRow.getTimestampFast(ResultSetRow.java:1335)
    at com.MysqL.jdbc.BufferRow.getTimestampFast(BufferRow.java:576)
    at com.MysqL.jdbc.ResultSetImpl.getTimestampInternal(ResultSetImpl.java:6466)
    at com.MysqL.jdbc.ResultSetImpl.getTimestamp(ResultSetImpl.java:6066)
    at com.MysqL.jdbc.ResultSetImpl.getTimestamp(ResultSetImpl.java:6104)
    at org.apache.tomcat.dbcp.dbcp.DelegatingResultSet.getTimestamp(DelegatingResultSet.java:300)
    at org.apache.tomcat.dbcp.dbcp.DelegatingResultSet.getTimestamp(DelegatingResultSet.java:300)
    at org.apache.tomcat.dbcp.dbcp.DelegatingResultSet.getTimestamp(DelegatingResultSet.java:300)

DAO类最近没有被修改过.服务器上最近唯一的变化是将MysqL从5.1.46升级到5.1.51

最佳答案
您可以通过向JDBC连接URL添加useFastDateParsing = false来禁用快速日期分析.例如,以下可能会解决您的问题:

jdbc:MysqL://yourHostName:3306/yourDbName?useUnicode=true&useFastDateParsing=false&characterEncoding=UTF-8

猜你在找的MySQL相关文章