How to handle date in java, if date value is: "0000-00-00 00:00:00". I am fetching data from mysql and meet with such kind of situation with date. Please suggest how to handle such scenarios.
Asked
Active
Viewed 1,909 times
1 Answers
5
Set the MySQL JDBC driver option zeroDateTimeBehavior=convertToNull
. You can set it in the connection string. Then you won't get these dates, you will get nulls instead.

user207421
- 305,947
- 44
- 307
- 483
-
In java side i can't handle ?? – Srishti Feb 21 '18 at 04:19
-
No, because you will get it from `ResultSet.getDate()` or `ResultSet.getObject()`, and it is already too late. Setting this option in the connection string can be done in Java, if you insist. – user207421 Feb 21 '18 at 04:22
-
@BleedCode Of course you can handle in Java side but I believe it will not be a preferrable way. You could retrieve the date as String, and do your special parsing logic. Or, make your SQL to retrieve null (or some other special date value) when the date is zero – Adrian Shum Feb 21 '18 at 05:19