Java PreparedStatement setString changes characters

牧云@^-^@ 提交于 2019-12-01 22:37:36

Sounds like a character encoding issue to me. Perhaps the driver is transcoding your strings into the appropriate encoding for the field/table/schema/database rather than letting the server do it? If you are trying to store a character which has no representation in the encoding of the field/table/schema/database, that would explain the '?' characters.

oezi

this normally happens by using different charsets in different locations. sound like you're getting your input as UTF-8, converting it to another chatset (maybe your database is set to something else) which breaks the special character.

to fix this: use the same charset everywhere*. (i would recommend using UTF-8)

*take a look at this or my answer to another thread (that's about a problem in php, but in java it's almost the same)

Are you using Oracle? I have had similar situations, if the environment variables regarding character sets weren't defined correctly.

By default, an Oracle connection is ASCII (7-bit characters, A-Z, a-z, numbers, punctuation, ...). If you use any character outside of that (e.g. European accents, Chinese characters, ..) then you need to use something other than ASCII. UTF-8 is best. If you don't, your characters will get replaced by "?".

You'd need to get your sysadmin to set this up for you. Alternatively take a look here:

http://arjudba.blogspot.com/2009/02/what-is-nlslang-environmental-variable.html

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