Kevin-sage () said:
Haha, it won't work after it is added. No reason
Said:
It's garbled in MySQL.
Kevin-sage () said:
Dizzy, that still won't work
Said:
You see string url = "JDBC: mysql: // localhost: 3306/yappt_srv? Useunicode = true & characterencoding = GBK ";
Said:
Right
Kevin-sage () said:
Right
Kevin-sage () said:
What is the encoding of your MySQL database?
Said:
Default-character-set = gb2312
Kevin-sage () said:
I don't know why. This is annoying Chinese.
Said:
I have reinstalled MySQL.
Said:
My code:
-----------
String r = "insert into t_addramount values ('xxxxxx', 'dmf0002', '(between 10 thousand and 0.2 million, must be an integer multiple of 2000 yuan)', '2017-01-01 ', '2017-12-30 ','');";
String des = new string (R. getbytes ("GBK"), "UTF-8 ");
System. Out. println (DES );
Stat.exe cute (DES );
-
R: Chinese characters are displayed;
But when it comes to DES, the output is: insert into t_addramount values ('xxxxxx', 'dmf0002 ',' (1 ?? 20 ?????,????????????) ', '2017-01-01', '2017-12-30 ', '');
However, if the conversion is not performed, an error occurs in execute.
Kevin-sage (said:
I don't know how to solve this problem. If you use hibernate, you can use the hibernate API to solve the problem.
Said:
Useunicode = true & characterencoding = UTF-8 ";
Said:
What does this mean?
Can use Unicode encoding and UTF-8?
Kevin-sage () said:
Indicates whether useunicode uses the specified encoding.
Kevin-sage () said:
When creating a table in the database, the statement is: Create Table tbname (...) engine = MyISAM Character Set GBK collate gbk_chinese_ci;
The connection object connecting to the database in the program must be written as connection con = drivermanaager. getconnection ("JDBC: mysql ://... user = .. & Password =... & useunicode = true & characterencoding = GBK ");
Kevin-sage () said:
My colleague's solution. Try it.
Kevin-sage () said:
Modify the MySQL configuration file (My. ini in Windows) and set both default-character-set to utf8.
Kevin-sage () said:
Or GBK
Said:
I want to: String des = new string (R. getbytes ("GBK"), "UTF-8"); in this way, R is Chinese, des is garbled display it
Kevin-sage:
If the problem persists, you can convert the type from varchar
Nvarchar
Kevin-sage () said:
Which MySQL version do you use?
Said:
5.0
Kevin-sage () said:
Default MySQL Encoding
Said:
I chose GBK during installation, but in my. ini it is: lain1
Kevin-sage () said:
Your MySQL encoding may be UTF-8 by default. This problem occurs only when you forcibly convert it to GBK.
Kevin-sage () said:
The default encoding in Java is iso8859-1, if your storage encoding and Java inside the encoding is not uniform
Kevin-sage () said:
Chinese characters won't be recognized. You should first find the crux of the problem.
Said:
I think it is also a problem with my MySQL, because I was right after the development, and then I re-installed the system, MySQL also re-installed
Finally: It turns out that when MySQL is installed and the encoding method is selected, the encoding method must be checked.