• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Ecliipse Java does not Display Chinese and Greek Characters?

 
Ranch Hand
Posts: 271
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From Eclipse Java, I run a PHP script which has an embedded call to a cloud mySQL stored procedure.

mySQL Workbench can store and display Chinese characters correctly.

Eclipse returns the dataset correctly in English, but Chinese characters (and a Greek name) cannot be displayed properly.

This is what I 've tried so far:

(1) In mySQL, I created the table wikth this specification:
ENGINE=INNODB AUTO_INCREMENT= 2468 CHARACTER SET utf8 COLLATE utf8_general_ci;

(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 characters are displayed like this:
???(??)???

Do I have to download some font or char-set for the project library?

Additonal info re my environment
I am using Eclipse Oxygen.3a Release (4.7.3a
java -version -> 1.8.0_171
javac -version -> 1.8.0_144
I have loaded java-json.jar and mysql-connector-java-5.1.26.jar into my Referenced Libraries
 
AhFai Chan
Ranch Hand
Posts: 271
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ADDENDUM 2018-08-20 04:10PM

If I cut-n-paste the Chinese characters into System.out.println(),  Eclipse displays them correctly.
Therefore, it is somewhere between mySQL and json_encode() that something went awry.

Since I have both English, Spanish and Chinese character fields in a table, I was wondering whether I can have 2 different encoding, one for each corresponding field type.
 
Marshal
Posts: 79699
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for providing so much detail about the problem.
Don't know myself, but what happens if you change the encoding from Other UTF‑8 under No 4 to plain simple UTF‑8? Why are you using the 144 version of javac and the 171 version of java? I presume that correct display on the mySQL console means the data are actually encoded correctly in UTF‑8.

Adding discussion to our Eclipse forum.
 
Campbell Ritchie
Marshal
Posts: 79699
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

AhFai Chan wrote:. . . I was wondering whether I can have 2 different encoding . . . .

That sounds dangerous.
 
Marshal
Posts: 28295
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

AhFai Chan wrote:Chinese characters are displayed like this:
???(??)???



Then that means you have an encoding problem, not a font problem. If you were using a font which couldn't render the characters, you would be seeing rectangular boxes. Question marks means that the encoding you use to convert from chars to bytes isn't designed to handle the chars. In particular it means it isn't UTF-8, because that can handle all chars.

Unfortunately you've got a lot of place where encoding and decoding are happening. There's transfers between the database and Java code, and there's transfers from the web app to the client and back again. Trying to test all of those things at the same time is like trying to run 100 meters as fast as possible while juggling flaming chainsaws. It would be better to test each of them separately; write specific code just to do those individual tests.
 
A day job? In an office? My worst nightmare! Comfort me tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic