0.前言
JAVA數據類型 和 MYSQL的數據類型轉換,要注意tinyInt 類型,且存儲長度為1的情況。
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.
2.要注意下面這個提示
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
3.解決方案
tinyInt(1)
只用來代表Boolean含義的字段,且0代表False,1代表True。如果要存儲多個數值,則定義為tinyInt(N), N>1
。例如tinyInt(2)
- JDBC的URL增加 tinyInt1isBit=false參數,注意參數名區分大小寫,否則不生效
jdbc:mysql://${ucmha.proxy1_2.host}/${db.mysql.db}?tinyInt1isBit=false