Help with Displaying Chinese in Java from mySQL
Posted by: Arthur Chan
Date: August 23, 2018 10:49PM

From Eclipse Java, I run a PHP script which executes a stored procedure in a cloud mySQL database

mySQL Workbench can store and display Chinese characters correctly.

Eclipse returns the dataset correctly in English, but Chinese characters cannot be displayed properly.

This is what I 've tried so far:

(1) In mySQL, I created the table wikth this specification:

(2) In the PHP script, I specified the header like this:
header("Content-type:application/json; charset=UTF-8");

(3) The response is json_encoded, like this:
echo json_encode(array("db_response"=>$response));

(4) And in Eclipse, I've set thre preference to utf-8, like this:
Window -> Preferences -> General -> Workspace -> title file encoding Other UTF-8

Chinese (and other languages) characters are displayed like this on both Firefox and Eclipse-Java app

All records in English are displayed correctly.

This is the setup I have in mySQL:
character_set_client utf8mb4
character_set_connection utf8mb4
character_set_database utf8mb4
character_set_filesystem binary
character_set_results utf8mb4
character_set_server latin1
character_set_system utf8
collation_connection utf8mb4_unicode_ci
collation_database utf8mb4_unicode_ci
collation_server latin1_swedish_ci

I do not know why the collation_server is set to "swedish"
I do not have a my.ini or my.cnf when I installed mySQL Workbench, so Icreated one myself.

Options: ReplyQuote

Written By
Help with Displaying Chinese in Java from mySQL
August 23, 2018 10:49PM

Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.