Java String - Fetching other languages character from mysql - Is the data complete? [closed]

核能气质少年 提交于 2019-12-13 10:17:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!