本文介绍了无法将值"2012-04-05 10:20:00"从XX列转换为TIMESTAMP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当JDBC尝试将MySQL(5.1.51)中的有效日期时间转换为java.sql.timestamp时,将引发java.sql.SQLException.一个例子是:
A java.sql.SQLException is being thrown when JDBC attempts to convert a valid datetime in MySQL (5.1.51) to a java.sql.timestamp. An example is:
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
DAO classes have not been modified recently. The only recent change on the server was upgrading MySQL from 5.1.46 to 5.1.51
推荐答案
您可以通过在JDBC连接URL中添加useFastDateParsing = false来禁用快速日期解析.例如,以下方法可以解决您的问题:
You could disable Fast Date Parsing by adding useFastDateParsing=false to your JDBC connection URL. For example the following might solve your problem:
jdbc:mysql://yourHostName:3306/yourDbName?useUnicode=true&useFastDateParsing=false&characterEncoding=UTF-8
这篇关于无法将值"2012-04-05 10:20:00"从XX列转换为TIMESTAMP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!