This is frustrating. When I run the following program I see “Garci?a” in the console instead of “García”, whereas if I run it in the Eclipse debugger, garciaString contains “García”. What’s going on? Is the problem in System.out? Do I have to configure it specially to print Unicode?
package com.example.unicode;
public class UnicodeTest {
public static void main(String[] args) {
String garciaString = "Garci\u0301a";
System.out.println(garciaString);
}
}
edit: I figured maybe the console doesn’t print the right value because of fonts. But I also get “Garci?a” inserted in an SQL database. Does JDBC + SQL handle Unicode? If not, how do I handle INSERT INTO mydb (id, name) VALUES (1, "Garci\u0301a")?
This means that the Eclipse console is not using UTF-8 encoding. You have to change it in preferences. See Getting Unicode output in Eclipse Console and this article.