Question: When Unbuntu used Eclipse to write a program, it found that the Chinese characters that were stored in the database MySQL became the???
Cause: The default encoding for Eclipse and MySQL is inconsistent
Workaround: Set both the Eclipse and MySQL encoding methods to UTF8
1. Set MySQL default encoding mode to UTF8
Modify the my.cnf file for the MySQL database, the my.cnf file path is/ETC/MYSQL/MY.CNF
Add under [client]
default-character-= UTF8
Add below [mysqld]
character-set-server = UTF8
Add below [MySQL]
default-character-= UTF8
Then save the file and restart the MySQL database with the following command
Sevice MySQL Restart
Note the database established after restarting the database is the default encoding UTF, and the previously established database encoding is unchanged
You can use the following command to view the database encoding
" %character% ";
2. Set Eclipse Project encoding to UTF8
Right-click Project--Select Properties--text file Encoding--other--utf-8--apply--ok
Java processing database MySQL character display garbled problem