简体   繁体   中英

Character encoding issue with linux and mysql

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

I am using hibernate 3.3 with mysql 5.5 (both windows and linux) and database usage default encoding (latin1).

I have tried setting -Dfile.encoding=UTF8 in JAVA_OPT but not worked, i think its this is os related problem.

Any suggestion?

(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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM