Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot convert value '2012-04-05 10:20:00' from column XX to TIMESTAMP

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

This is the first time

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

stack trace:

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 classes have not been modified recently. The only recent change on the server was upgrading MySQL from 5.1.46 to 5.1.51

like image 381
Fred Avatar asked Apr 23 '12 01:04

Fred


1 Answers

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
like image 181
Youness Avatar answered Sep 30 '22 05:09

Youness