Database version: Oracle 10g
Character set: Simplified Chinese_china. Us7ascii
Jdk:1.6.0_45
Oracle Driver: Ojdbc14.jar
Use JDBC to manipulate the database, get connections, execute SQL without problems. However, the results of the query, all Chinese characters, are displayed as garbled.
Debug check See in the data from the database to get out of the time, is already garbled, and using PL/SQL and other tools, are displayed normal.
I do not know whether the driver of Oracle, in the processing of Chinese characters, the use of the system default character set? At this time, the spirit of the dead horse as a living horse medical philosophy, the use of the forced transcoding of Chinese characters, ASCII code is the standard iso-8859-1 subset, perhaps use this iso-8859-1 can get to normal Chinese characters? So, first test using new String (Fieldvalue.getbytes ("iso-8859-1")); the output is still garbled! Think of it as a transcoding, not just in this format, so the adjustment is: New String (Fieldvalue.getbytes ("iso-8859-1"), "GBK"), tested, done! Just, all the places that use Chinese characters, all need to do so, a little trouble.
It is said that you can use another way: Change the Oracle Character set!
1, need to modify the registry: Hkey_local_machine\software\oracle\home0\nls_lang value is simplified Chinese_china. Zhs16gbk
2, modify a system variable Nls_lang.
Two of the above, the second way tried, can. First, no tests have been done in the existing environment.
In addition, the acquisition of Chinese characters, written to another Oracle 11g database, found that: Chinese characters are not according to a Chinese character two bytes to store, but a Chinese character 3 bytes!
Looked up, found: The character set is Al32utf8, this character set is generally the default Chinese is 3 bytes. Therefore, the field length of the target database table needs to be expanded. The actual problem with the Chinese characters, oralce and newer SQL Server, both support the nvarchar format, for the use of nvarchar fields, regardless of Chinese characters or numbers, characters, English letters, each character occupies 1 bits.
If you are not sure that the current character occupies a few characters, you can use Select Length (' Khan ') from dual;
For the us7ascii character set, for the time being, the new system is less used, and for some older legacy systems, this may be the case. Specific also need to pay attention!
JDBC reads the US7ASCII encoding of Oracle and the problem of Chinese characters occupying bytes under different codes