[英]how to read and store non-English character in java on windows os
I am dealing with a Brazilian customer where the data is in Portuguese language. 我正在与巴西客户打交道,那里的数据是葡萄牙语。
My application is responsible to read the data through web-service calls and store it in our database. 我的应用程序负责通过Web服务调用读取数据并将其存储在我们的数据库中。 The issue that I am currently facing is the Portuguese characters are not getting identified as it is and is stored in my database as a special character. 我当前面临的问题是葡萄牙语字符无法被原样识别,而是作为特殊字符存储在数据库中。
I am using MySQL database with all tables configured as collation UTF-8. 我正在使用所有表都配置为排序规则UTF-8的MySQL数据库。 I tried manually inserting Portuguese character into my database and it worked. 我尝试将葡萄牙语字符手动插入到我的数据库中,并且可以正常工作。 So I am suspecting its java who is converting the Portuguese characters into special character. 因此,我怀疑它的java会将葡萄牙语字符转换为特殊字符。
Also, my application is using Hibernate for database operations. 另外,我的应用程序使用Hibernate进行数据库操作。
I am able to get the character as I see in logs and the issue reside while trying to store that data in database. 我能够获得在日志中看到的字符,并且尝试将数据存储在数据库中时问题仍然存在。
Eg: Original characters: Gerãt
Database characters: Gerãt
What configurations or setting or changes I need to do to my database so that I can capture the data in Portuguese language as it is? 我需要对数据库进行哪些配置或设置或更改,以便可以按葡萄牙语原样捕获数据?
It may not be database issue, but an application configuration issue. 可能不是数据库问题,而是应用程序配置问题。
Few pointers to help : 很少有帮助的指针:
Hope it helps. 希望能帮助到你。
Try changing your hibernate configuration to: 尝试将您的休眠配置更改为:
<hibernate-configuration>
<session-factory>
<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">UTF-8</property>
<property name="connection.charSet">UTF-8</property>
If that doesn't work, try adding UTF-8
to your characterEncoding
in your JDBC url. 如果这不起作用,请尝试将UTF-8
添加到JDBC url中的characterEncoding
中。
Also, this question might help you: Cannot insert non latin symbols in MySQL 另外,此问题可能对您有所帮助: 无法在MySQL中插入非拉丁符号
This worked in my case: 这在我的情况下有效:
Add environment variable JAVA_TOOL_OPTIONS instead of _JAVA_OPTIONS with value as 添加环境变量JAVA_TOOL_OPTIONS而不是_JAVA_OPTIONS ,其值为
-Dfile.encoding=UTF8
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.