Java/groovy error - "can not be represented as java.sql.Timestamp"

0000-00-00 00:00:00^@' can not be represented as java.sql.Timestamp

If you ever get the above error when parsing dates using java or groovy and the data you are getting is from MySQL then just add

?zeroDateTimeBehavior=convertToNull
to your connection string.

def sth   = Sql.newInstance('jdbc:mysql://hostname:port/dbname?zeroDateTimeBehavior=convertToNull&characterEncoding=utf-8&useUnicode=true', 'user', 'password', 'com.mysql.jdbc.Driver')

Then any dates that were 0000-00-000 will come out as null and the code wont error. This is my solution anyway and it took me a while to find it. Hopefully this will help someone else that isn't really all that sure about groovy/java.

  • java, (1)
  • mysql, (1)
  • groovy (1)