为什么 mysql-connector 将 YEAR(4) 视为日期?

Why does mysql-connector tread YEAR(4) as Date?

https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-configuration-properties.html

yearIsDateType

Should the JDBC driver treat the MySQL type "YEAR" as a java.sql.Date, or as a SHORT?

Default: true

问题:如果YEAR(4)mysql中的Integer(默认情况下是),为什么mysql-connector java驱动程序然后踩年份值为 Date?

我的意思是,这个默认配置是否有意义?

因为:如果您不仔细查看数据库,您会假设 2017-01-01 等值直接来自数据库。但是,数据库仅将 2017 作为年份值保存,而 java 会默默地添加月份的第一天。

文档是这样说的:

YEAR[(2|4)]

YEAR

If yearIsDateType configuration property is set to false, then the returned object type is java.sql.Short. If set to true (the default), then the returned object is of type java.sql.Date with the date set to January 1st, at midnight.

来源:https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-type-conversions.html