Search code examples
javaspringwordpresspojo

Cast to Timestamp in Java


i need a support,

i want to create product importer to woocommerce in Java.

One of column in "wp_posts" table is Timestamp type. But unfortunatelly if in wordpress i won't publicate a post/product, value of this field is "0000-00-00 00:00:00".

When my code try to cast the post to POJO Object, i have error:

java.sql.SQLException: Value '......' can not be represented as java.sql.Timestamp.

How should i cast "0000-00-00 00:00:00" to Timestamp in Java?


Solution

  • I believe this is caused by JDBC, add zeroDateTimeBehavior=convertToNull at the end of the jdbc connection string will fix. like this

    jdbc:mysql://127.0.0.1:3306?zeroDateTimeBehavior=convertToNull
    

    Refer: https://github.com/prestodb/presto/issues/2326