Problem description
TinyInt data type, in Java data type and MySQL data type conversion, pay attention to the case of storage length of 1. Query, the Java type of the field corresponds to a Boolean
Source data:
Post-read data:
Problem analysis
The MySQL official JDBC document definition conversion rules are as follows:
If Tinyint1isbit=true (default), and the tinyint storage length is 1, it is converted to Java.lang.Boolean, otherwise to Java.lang.Integer.
Solution Solutions
1. Avoid using a tinyint type field of length 1 to store data in a number format, tinyint (1) is used only to represent a Boolean-meaning field. where 0 represents true for false,1. If you want to store multiple values, it is defined as tinyint (N), n>1. For example TINYINT (2)
2, the JDBC URL increases the tinyint1isbit=false parameter, note the parameter name is case-sensitive, otherwise does not take effect.
Final private Val URL = "jdbc:mysql://localhost:3306/test_db?useunicode=true&characterencoding=utf-8& Zerodatetimebehavior=converttonull&tinyint1isbit=false&serverTimezone=Asia/Shanghai& Usessl=true "
Amazing MySQL!~~
MySQL "tinyint1isbit or tinyint (1)" Related problem analysis