问题
Is the Java String data that I will fetch complete if I have special characters like japanese, greek, chinese, korean, etc. characters stored in my mysql database?
To be clear my question is will the special characters that I fetched in mysql complete if I stored them in java string, and will I able to display them in character form when I use them for text components like JEditorPane
String data;
ResultSet r = sabiNa.executeQuery();
while(r.next()) {
data = r.getString("data");
}
回答1:
Java is capable of storing ALL valid Unicode text. It uses UTF-16 internally.
If you configure the entire data path correctly, all text will be preserved. You need to ensure:
- The correct string reaches Java (in case of web applications, character encoding of the form being submitted).
- Java knows it should be talking to the database in UTF-8 and the database knows it should be expecting UTF-8 through the connection. You ensure this when setting up the database connection.
- Data is stored as UTF-8 in the database.
Note that [the documentation for MySQL] claims UTF-8 is incapable of storing characters outside the Basic Multilingual Plane (all "normal" characters lie within BMP). UTF-8 itself is perfectly capable of storing all unicode characters and the database should be able to encode these characters as well.
Java itself is fine - just remember some rare unicode characters are actually two characters (called a surrogate pair) in Java.
来源:https://stackoverflow.com/questions/13085133/java-string-fetching-other-languages-character-from-mysql-is-the-data-comple