JAVA数据类型 和 MYSQL的数据类型转换,要注意tinyInt 类型,且存储长度为1的情况。
mysql文档给出的解释
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.
要注意下面这个提示
The ResultSet.getObject()
method uses the type conversions between MySQL and Java types, following the JDBC specification where appropriate. The values returned by ResultSetMetaData.GetColumnTypeName()
and ResultSetMetaData.GetColumnClassName()
are shown in the table below. For more information on the JDBC types, see the reference on the java.sql.Types class.
文档地址:https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-type-conversions.html
解决方案
1、tinyInt(1)
只用来代表Boolean含义的字段,且0代表False,1代表True。如果要存储多个数值,则定义为tinyInt(N), N>1
。例如 tinyInt(2)
2、JDBC的URL增加 tinyInt1isBit=false参数,注意参数名区分大小写,否则不生效
jdbc:mysql://${ucmha.proxy1_2.host}/${db.mysql.db}?tinyInt1isBit=false