jdbc connects to mysql, inserting Chinese fields with garbled characters

Recently, I was learning the orm framework, the fields in the inserted objects contained Chinese characters, and I found that the Chinese fields in the database table were ???

Solution process:

  1. The url value is changed from jdbc:mysql://localhost:3306/test to jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8
  2. Change the project encoding format to utf8
  3. Query current database character encoding SHOW VARIABLES LIKE "character%";  
    1. found | character_set_database and character_set_server are latin1 
    2. set in my.ini
      1. default-character-set=utf8
      2. character-set-server=utf8
    3. restart mysql service
  4. The encoding format was not specified as utf8 when the table was built before, and the table was rebuilt
    1. CREATE TABLE bobo_user (
        user_id varchar(100),
        username varchar(30) ,
        nickname varchar(30),
        phone_number varchar(30) ,
        password varchar(30),
        PRIMARY KEY (user_id)
      )  DEFAULT CHARSET=utf8;

       

    problem solved

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325983440&siteId=291194637