问题描述
我正在从Web服务获取包含此子字符串gratuit.AFLĂMAI MULTEDe
的字符串.当我将其保存在本地(windows)数据库中时,工作正常,但是当我尝试将其部署在linux上时保存在服务器上时,出现以下错误:
I am getting this string which contains this substring gratuit.AFLĂ MAI MULTEDe
from webservice. when i save this in data base in my local(windows) works fine but when i try to save on server when it is deployed on linux i get following error:
Incorrect string value: '\xC4\x82 MAI...' for column 'description' at row 1
我正在将hibernate 3.3与mysql 5.5(Windows和linux)以及数据库使用默认编码(latin1)一起使用.
I am using hibernate 3.3 with mysql 5.5 (both windows and linux) and database usage default encoding (latin1).
我尝试在JAVA_OPT中设置 -Dfile.encoding = UTF8
,但是没有用,我认为这是与操作系统相关的问题.
I have tried setting -Dfile.encoding=UTF8
in JAVA_OPT but not worked, i think its this is os related problem.
有什么建议吗?
推荐答案
(通常,如今,我会在UTF-8中进行所有操作.)可以设置编码的点很长.从Web服务中,您可能会获得UTF-8中的XML.由于XML处理严格的编码,因此可以自动正确读取.
(In general nowadays I would do all in UTF-8.) There is a long pipeline of points where encoding can be set. From the web service you get probably XML in UTF-8. That is automatically read correctly, as XML handles the encoding strict.
在数据库级别,存在具有默认和显式编码的数据库,表和字段.此外,应将连接网址的参数设置为正确的编码.
On database level there is the database and table and field with a default and explicit encoding. Furthermore the connection url should be parametrised to the correct encoding.
错误消息显示该重音 A 的UTF-8字节,我想它在Latin1中不可用.对于MySQL,连接字符串可能类似于:
The error message shows the UTF-8 bytes for that accented A and I guess it is not available in Latin1.For MySQL the connection string could look like:
jdbc:mysql://localhost/MYDB?useUnicode=true&characterEncoding=UTF-8
这篇关于linux和mysql的字符编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!