MySQL "tinyint1isbit or tinyint (1)" Related problem analysis

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.