问题

在JAVA程序中查询mysql数据库带有tinyint(1)的字段的数据会被转换成boolean类型。

原因

mysqljdbc默认情况会把tinyint(1)当作boolean类型。

Table 6.2 MySQL Types and Return Values for ResultSetMetaData.GetColumnTypeName()and ResultSetMetaData.GetColumnClassName()

MySQL Type Name Return value of GetColumnClassName Return value of GetColumnClassName
TINYINT TINYINT java.lang.Boolean if the configuration property tinyInt1isBit is set to true (the default) and the storage size is 1, or java.lang.Integer if not.
BOOL, BOOLEAN TINYINT See TINYINT, above as these are aliases for TINYINT(1), currently.

翻译:
如果tinyInt1isBit =true(默认),且tinyInt存储长度为1 ,则转为java.lang.Boolean 。
否则转为java.lang.Integer。

资料链接
https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-type-conversions.html

解决办法

jdbc链接url上面加上tinyInt1isBit=false参数
例如: jdbc:mysql://:/?tinyInt1isBit=false