Database version number: 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, run SQL without problems. However, the query out of the results, 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 a standard subset of iso-8859-1, perhaps use this iso-8859-1 to get normal Chinese characters? So, first test using new String (Fieldvalue.getbytes ("iso-8859-1")), the output is still garbled! Think of this thing should be transcoded, but not in accordance with this format to obtain, so adjusted to: New String (Fieldvalue.getbytes ("iso-8859-1"), "GBK"), test, done! However, all the use of Chinese characters, all need to do so, a little trouble.
It is said to be able to use the second way: to change the Oracle character set!
1, need to change the register: Hkey_local_machine\software\oracle\home0\nls_lang value is simplified Chinese_china. Zhs16gbk
2, change a system variable Nls_lang.
Both of these, the second way tried, can. The first, not tested 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, all support the nvarchar format, for the use of nvarchar fields, regardless of Chinese characters or numbers, characters, English letters, each character occupies 1 bits.
Assuming that the current character is not determined to occupy a few characters, you can use Select Length (' Khan ') from dual;
For the us7ascii character set, for the moment, the new system is less used, and for some older legacy systems, there may be situations. Details also need to pay attention!
JDBC reads the US7ASCII encoding of Oracle and the problem of Chinese characters occupying bytes under different codes