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

Chamila Adhikarinayake picture Chamila Adhikarinayake · Jun 21, 2012 · Viewed 110.8k times · Source

I have a database table containing dates

 (`date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'). 

I'm using MySQL. From the program sometimes data is passed without the date to the database. So, the date value is auto assigned to 0000-00-00 00:00:00 when the table data is called with the date column it gives error

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

I tried to pass null value to the date when inserting data, but it gets assign to the current time.

Is there any way I can get the ResultSet without changing the table structure?

Answer

Kushan picture Kushan · Jun 21, 2012

You can use this JDBC URL directly in your data source configuration:

jdbc:mysql://yourserver:3306/yourdatabase?zeroDateTimeBehavior=convertToNull