I am having problems inserting chinese characters in MySQL. I am able to insert the chinese characters only in Query Browser / Workbench, but it comes out as '??' when using my开发者_StackOverflow program. I somehow managed to get it to work on my computer (Windows 7) , but when I tested it on another (Windows 7 too) , it came out as question marks. It also won't work on a Windows XP Chinese. Any help?
The driver is transferring in UTF-8 seeing your comment on the connection string. The database table fields are probably specified UTF-8 too (check this).
So you have a normal Unicode string in Java. Check that by a dump of String.getBytes("UTF-8")
. No question mark should appear.
In a web application you need to set the encoding before using the Writer. Otherwise you get such questing marks. Other possibilities to err are String.getBytes()
(default OS encoding), Writer on a FileOutputStream using a StreamOutputStream also without encoding.
1.use cmd to connect database for example:
D:\MySQL\bin>mysql -u root -D test -p
2.to change the database to UTF-8 for example:
mysql>alter database [database name] default character set utf8
精彩评论