Painstaking effort: perfect solution to Informix's Chinese garbled Problem

Source: Internet
Author: User
Tags informix

Informix is a database owned by IBM. If it weren't for this project, I don't even know that there is such a database in my life. I want to come to the company's projects all over the country, and there are all kinds of deployment environments and various application scenarios. I asked a lot of project teams and no one knows about this, it can be seen how small the goods are...

I was totally confused when I first started to get started with this stuff. Its design philosophy and usage were so strange that Nima, whether it was DB2, Oracle, or MySQL, no corresponding development experience can be applied directly to Informix, that is, it is much harder to find the corresponding documentation than other databases, it took me a lot of effort to make it easy.

If you don't talk nonsense, you can solve all the pain points in the Garbled text process and press "no table" for the moment. Let's go straight to the topic. First, record your experiences and the key points for solving the problem:

Key Aspect 1: correctly understand the four basic concepts required by the Informix database.

Meanings of the four language Environments:

1. Client locale
The client Language Environment specifies the language, region, and code set in which the client application is used to perform read and write (I/O) operations.
In client applications, I/O operations include reading data files input by the keyboard or to be sent to the database, and writing data retrieved from the database server to the screen, file, or printer.
Use client_locale to set the client language environment.

2. database language environment-database locale
The database language environment set through db_locale environment variables specifies the language, region, and code set required by the database server to correctly interpret the language environment-related data types (nchar and nvarchar) in a specific database.
The code set specified in db_locale determines which characters are valid in any character column, and determines the names of database objects (such as databases, tables, columns, and views.
The database server uses the database code set specified by the db_locale environment variable to pass data into and out of the database.

3. Server language environment-server locale
The database server uses the server code set specified by the server_locale environment variable to write files (such as debugging and warning files ).
However, the database server does not use the server language environment to write files (database and table files) in the Informix special format ).

4. server processing language environment-server processing locale
The database server uses the code set of the database language environment as the code set of the server's processing language environment, and uses the server's processing language environment to write files (database and table files) in the Informix special format ).
That is to say, the database server uses the database language environment (db_locale) to write files (database and table files) in the special Informix format ).


Key Aspect 2: Introduce the correct jdbc jar file.
The list of jar files is as follows. At least 10 jar files are required:
Ifxjdbc. Jar
Ifxjdbc-g.jar
Ifxjdbcx. Jar
Ifxjdbcx-g.jar
Ifxlang. Jar
Ifxlsupp. Jar
Ifxsqlj. Jar
Ifxsqlj-g.jar
Ifxtools. Jar
Ifxtools-g.jar

It is very important to emphasize this key point: theoretically, to enable Informix, you only need ifxjdbc. Jar. But without other jar files, your Chinese problems will never be solved! At the beginning, Lao Tzu introduced only five or six necessary jar files. At the end of the Code, it took most of the time to adjust the garbage codes.

Key Aspect 3: View All Database codes in the current system.
Select * From sysmaster: sysdbslocale
This statement can query the encoding formats used by all databases in the current database.

Key Aspect 4: Write the correct jdbc url.

Jdbc url (UTF-8 encoding example ):
JDBC: Informix-sqli: 6.1.14.38: 48101/ccdb2: informixserver = ccdb; newcodeset = utf8, 8859-1,819; client_locale = en_us.utf8; db_locale = en_US.8859-1;

Jdbc url (GBK encoding example ):
JDBC: Informix-sqli: 6.1.14.38: 48101/ccdb2: informixserver = ccdb; newcodeset = GB18030-2000, 8859-1,819; client_locale = zh_cn.gb; db_locale = zh_cn.gb;

This point must also be emphasized. Its importance is second only to key aspect 2. In Java, the encoding we use is called UTF-8, but in Informix, the correct writing of this encoding format is utf8, not UTF-8! In addition, GBK encoding is known as GB or GB18030-2000 in Informix systems. If you write GBK in a URL, it cannot be identified.


Key Aspect 5: confirm that the Informix server supports the UTF-8 format.
Use the locale-a command and then check if zh_cn.utf8 is supported (note en_US.UTF-8 is also supported)

Key Aspect 6: encoding adjustment of the Client Connection Tool.
Note: When you use securecrt to display the zh_cn.utf8 character, you should select the UTF-8 when in session options-> terminal-> appearance exact font, otherwise it will show garbled characters.

Summary:

Key Aspect 2 and key aspect 4 are the top priority to solve the problem of Informix garbled characters. As long as the two key points do not solve the problem, Chinese will certainly be able to read and write to the database normally. In addition, it should be noted that this solution is only applicable to Informix deployed on Linux/Unix and is effective in testing. A database is deployed on a Windows server, which is too expensive.

 

Document Information
  • Translator: Uncle Zhang
  • Http://www.cnblogs.com/flance/
  • Copyright statement: Free Reprint-non commercial-Non derivative-keep the signature | Creative Commons BY-NC-ND 3.0

Painstaking effort: perfect solution to Informix's Chinese garbled Problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.