java - JDBC访问数据库, set names utf8 无法解决乱码问题.
PHP中文网
PHP中文网 2017-04-18 10:11:59
0
1
588
PHP中文网
PHP中文网

认证0级讲师

reply all(1)
伊谢尔伦

The reason for the problem is that the default connection is gbk encoding

The solution is as follows:
Find the mysql configuration file my.cnf, and then configure it as follows:

Client configuration [client] Add
default-character-set=utf8 below //The default character set is utf8
Find [mysqld] and add
default-character-set=utf8 //The default character set is utf8
init_connect= 'SET NAMES utf8' //(Set to use utf8 encoding when connecting to the mysql database so that the mysql database runs as utf8)

Then restart mysql, and then run the command just now. After it is utf-8, you can directly use insert into in the java program without the need for the previous set names

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!