当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
答案 0 :(得分:5)
您可以通过向JDBC连接URL添加useFastDateParsing = false来禁用快速日期分析。例如,以下内容可能会解决您的问题:
jdbc:mysql://yourHostName:3306/yourDbName?useUnicode=true&useFastDateParsing=false&characterEncoding=UTF-8
答案 1 :(得分:0)
我可以建议:
DEBUG
您的DAO
并查看您的Sql Query
并尝试在MySQL中输入手册,您会发现问题更加轻松。