When using resultset in MySQL development, both getstring () or getdate (), or GetObject, are thrown out title the exception. Check MySQL official Bug Advisory:
It is because the MySQL preset is thrown out of the exception (exception) when the string of the date type (date or datetime type) is ' 000-00-00 '. Simply modify the JDBC database connection string as follows:
The pre-modification JDBC Connection string is:
Jdbc:mysql://localhost:3306/test?characterencoding=utf-8&charactersetresults=utf-8
After modifying the JDBC connection string:
jdbc:mysql://localhost:3306/test?characterencoding=utf-8&charactersetresults=utf-8& Zerodatetimebehavior=converttonull
The original text reads as follows:
DateTimes with All-zero components (0000-00-00 ...)-these values can is not a represented reliably in Java. Connector/j 3.0.x always converted them to NULL when being read from a resultset.connector/j 3.1 throws an exception by de Fault when these values was encountered as this was the most correct behavior according to the JDBC and SQL standards. This behavior can is modified using the Zerodatetimebehavior configuration property. The allowable values Are:exception (the default), which throws an SQLException with an SQLState of S1009.converttonull, WH Ich returns NULL instead of the Date.round, which rounds the date to the nearest closest value which is 0001-01-01.startin G with Connector/j 3.1.7, resultset.getstring () can is decoupled from this behavior via Nodatetimestringsync=true (The Def Ault value is false) so, you can retrieve the unaltered All-zero value as a String. It should is noted that this also precludes using any time zone conversions, therefore the driver won't allowYou-enable Nodatetimestringsync and Usetimezone at the same time.
mssql-exception value ' 0000-00-00 ' can not is represented as Java.sql.Date