MySQL, JDBC Driver and zero dates

I am in the middle of moving a lot of my datasources over to the updated Connector/J (JDBC)

One error I have seen a lot in my development enviorment is


Error Executing Database Query.<br/>
Cannot convert value '0000-00-00 00:00:00' from column xxxx to TIMESTAMP.

This is caused by Java as it cannot handle zero dates ('0000-00-00 00:00:00'), it trys to do anything it can with them but convert them to the original date :o). To get round this you can set a parameter in the JDBC URL called zeroDateTimeBehavior to convertToNull.

So in your Data Sources page you should have something similar to:


jdbc:mysql://localhost:3306/mySqlDatabase?zeroDateTimeBehavior=convertToNull

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
djhunx's Gravatar Hi, I'm working on a small program that uses a mysql database with some of the date fields default to '0000-00-00 00:00:00'. I've searched the internet for a solution and found yours to be the one I need. Thanks...
# Posted By djhunx | 8/18/07 7:39 PM
Patty's Gravatar This tip works from CF8 Administrator as well:

Data -> Services -> Datasources -> MySQL(4/5)
Advanced Settings
Add: zeroDateTimeBehavior-convertToNull
to the Connection String Field

Thanks for the tip! Solved my issues too!
Good Work!
# Posted By Patty | 1/7/08 2:00 PM
Joe's Gravatar Helped me out, thanks!
# Posted By Joe | 2/5/08 11:01 AM
Adi's Gravatar Thanks for the tip! Solved my problem !!
# Posted By Adi | 2/24/08 12:35 AM
shaunw's Gravatar Thanks Andy and Patty!

added...
zeroDateTimeBehavior=convertToNull
...to the connection string field in the CF8 admin for the MySQL4/5 DSN
# Posted By shaunw | 3/24/08 7:02 AM
Kirk's Gravatar Just what I needed. This made my week, thanks.
# Posted By Kirk | 4/14/08 10:24 AM
Madhav's Gravatar Thanks Andy. You certainely made my day
# Posted By Madhav | 7/24/08 7:11 AM
hmart's Gravatar Thanks Andy, I had this error connecting a Mysql DB using Eclipse SQL Explorer Plugin With Myslq J Connector 5.1.
Solved!
# Posted By hmart | 10/19/08 6:11 PM
BlogCFC was created by Raymond Camden / Contact Blog Owner / mptooling.com / spicemerchants-portsmouth.co.uk / ipicture.it