informix
Informix JDBC Driver Programmer's Guide
Programming with Informix JDBC Driver

Internationalization

Internationalization allows you to develop software independently of the countries or languages of its users and then to localize your software for multiple countries or regions. Informix JDBC Driver extends the Java JDK 1.2 internationalization features by providing access to Informix databases that are based on different locales and code sets.

JDK 1.1 and 1.2 Internationalization Support

Versions 1.1 and 1.2 of the JDK provide a rich set of APIs for developing global applications. These internationalization APIs are based on the Unicode 2.0 code set and can adapt text, numbers, dates, currency, and user-defined objects to any country's conventions.

The internationalization APIs are concentrated in three packages:

For more information about JDK internationalization support, consult this Web site:

Warning: There is no connection between JDK locales and JDK code sets: you must keep these in agreement. For example, if you select the Japanese locale ja_JP, there is no Java method that tells you that the SJIS code set is the most appropriate.

Support for Informix GLS Variables

For general information about setting up Informix global language support (GLS), refer to the Informix Guide to GLS Functionality.

Internationalization adds several new environment variables to Informix JDBC Driver:

The locale environment variables are available on and optional for Informix servers that support GLS:

The DB_LOCALE and CLIENT_LOCALE values must be the same, or their code sets must be convertible. For more information, see the Informix Guide to GLS Functionality.

The GL_DATE, DBDATE, and DBCENTURY variables are described in the following section.

Important: The DB_LOCALE, CLIENT_LOCALE, and GL_DATE variables are supported only if the database server supports the Informix GLS feature. If these environment variables are set and your application connects to a non-GLS server (server versions earlier than 7.2), a connection exception occurs. If you connect to a non-GLS server, the behavior is the same as for Informix JDBC Driver Version 1.22.

Support for Date End-User Formats

The date end-user format is the format in which a date appears in a string variable. This section describes the GL_DATE, DBDATE, and DBCENTURY variables, which specify date end-user formats. These variables are optional.

GL_DATE Variable

The GL_DATE environment variable specifies the end-user formats of values in DATE columns. This variable is supported in Informix database servers 7.2x and beyond. A GL_DATE format string can contain the following characters:

Date formatting directives are defined in the following table.

Directive Replaced By
%a The abbreviated weekday name as defined in the locale
%A The full weekday name as defined in the locale
%b The abbreviated month name as defined in the locale
%B The full month name as defined in the locale
%C The century number (the year divided by 100 and truncated to an integer) as a decimal number (00 through 99)
%d The day of the month as a decimal number (01 through 31). A single digit is preceded by a zero (0).
%D Same as the %m/%d/%y format
%e The day of the month as a decimal number (1 through 31). A single digit is preceded by a space.
%h Same as the %b formatting directive
%iy The year as a two-digit decade (00 through 99). It is the Informix-specific formatting directive for %y.
%iY The year as a four-digit decade (0000 through 9999). It is the Informix-specific formatting directive for %Y.
%m The month as a decimal number (01 through 12)
%n A newline character
%t The TAB character
%w The weekday as a decimal number (0 through 6); 0 represents the locale equivalent of Sunday.
%x A special date representation that the locale defines
%y The year as a two-digit decade (00 through 99)
%Y The year as a four-digit decade (0000 through 9999)
%% % (to allow % in the format string)

Important: GL_DATE optional date format qualifiers for field specifications (for example %4m to display a month as a decimal number with a maximum field width of 4) are not supported.

Informix JDBC Driver does not support ALS 6.0, 5.0, or 4.0 era-based formats in the DBDATE and GL_DATE environment variables.

The GL_DATE conversion modifier O, which indicates use of alternative digits for alternative date formats, is not supported.

White space or other nonalphanumeric characters must appear between any two formatting directives. If a GL_DATE variable format does not correspond to any of the valid formatting directives, errors can result when the database server attempts to format the date.

For example, for a U.S. English locale, you can format an internal DATE value for 09/29/1998 using the following format:

To create this format, set the GL_DATE environment variable to this value:

To insert this date value into a database table that has a date column, you can perform the following types of inserts:

The following example shows both types of inserts:

To retrieve the formatted GL_DATE DATE value from the database, call the getString() method of the ResultSet class. To enter strings that represent dates into database table columns of char, varchar, or lvarchar, you can also build date objects that represent the date string value. The date string value must be in GL_DATE format. The following example shows both ways of selecting DATE values:

DBDATE Variable

Support for the DBDATE environment variable provides backward compatibility for client applications that are based on Informix database server versions prior to 7.2x. Informix recommends that you use the GL_DATE environment variable for new applications.

The DBDATE environment variable specifies the end-user formats of values in DATE columns. End-user formats are used in the following ways:

With standard formats, you can specify the following attributes:

The format string can include the following characters:

The following format strings are valid standard DBDATE formats:

The separator always goes at the end of the format string (for example, DMY2/). If no separator or an invalid character is specified, the slash ( / ) character is the default.

For the U.S. ASCII English locale, the default setting for DBDATE is Y4MD-, where Y4 represents a four-digit year, M represents the month, D represents the day, and hyphen ( - ) is the separator (for example, 1998-10-08).

To insert a date value into a database table with a date column, you can perform the following types of inserts:

The following example shows both types of inserts (the DBDATE value is MDY2-):

To retrieve the formatted DBDATE DATE value from the database, call the getString method of the ResultSet class. To enter strings that represent dates into database table columns of char, varchar, or lvarchar, you can build date objects that represent the date string value. The date string value needs to be in DBDATE format. The following example shows both ways to select DATE values:

Important: Informix JDBC Driver does not support ALS 6.0, 5.0, or 4.0 era-based formats in the DBDATE and GL_DATE environment variables.

DBCENTURY Variable

The DBCENTURY environment variable enables you to choose the appropriate four-digit year expansion for one- or two-digit year DATE and DATETIME values. See the Informix Guide to SQL: Reference for detailed information about this environment variable.

Informix JDBC Driver accepts the DBCENTURY value but does not use it to expand a two-digit year to a four-digit year. When you specify a two-digit year, Informix JDBC Driver supplies the first two digits of the current year. For example, in 1999, the driver supplies 19; in 2000, the driver supplies 20.

Informix JDBC Driver always includes four-digit years when it sends java.sql.Date and java.sql.Timestamp values to the server. Similarly, the server always includes four-digit years when it sends Informix date and datetime values to Informix JDBC Driver.

Informix JDBC Driver also does not use the DBCENTURY value for string-to-date value conversion. Informix JDBC Driver performs string-to-date, string-to-datetime, and string-to-timestamp conversions under these circumstances:

Precedence Rules Regarding DATE Value End-User Formats

The precedence rules that define how to determine an end-user format for an internal DATE value are listed here:

Support for Code-Set Conversion

Code-set conversion converts character data from one code set (the source code set) to another (the target code set). In a client/server environment, character data might need to be converted from one code set to another if the client and database server computers use different code sets to represent the same characters. For detailed information about code set conversion, see the Informix Guide to GLS Functionality.

You must specify code set conversion for the following types of character data:

Informix JDBC Driver converts character data as it is sent between client and database server. The code set (encoding) used for the conversion is specified in the systables catalog for the opened database. You set the DB_LOCALE and CLIENT_LOCALE values in the connection properties or database URL.

Unicode to Database Code Set

Java is Unicode based, so Informix JDBC Driver converts data between Unicode and the Informix database code set. The code set conversion value is extracted from the DB_LOCALE value specified at the time the connection is made. If this DB_LOCALE value is incorrect, the database locale (stored in the database systables catalog) is used in the connection and in the code set conversion.

The DB_LOCALE value must be a valid Informix locale, with a valid Informix code set name or number as shown in the compatibility table that follows. The following table maps the supported JDK 1.2 encodings to Informix code sets.

Informix Code Set Name Informix Code Set Number JDK Code Set
8859-1 819 8859_1
8859-2 912 8859_2
8859-3 57346 8859_3
8859-4 57347 8859_4
8859-5 915 8859_5
8859-6 1089 8859_6
8859-7 813 8859_7
8859-8 916 8859_8
8859-9 920 8859_9
ASCII 364 ASCII
sjis-s 932 SJIS
utf8 57372 UTF8
big5 57352 Big5
CP1250 1250 Cp1250
CP1251 1251 Cp1251
CP1252 1252 Cp1252
CP1253 1253 Cp1253
CP1254 1254 Cp1254
CP1255 1255 Cp1255
CP1256 1256 Cp1256
CP1257 1257 Cp1257
cp949 57356 Cp949
KS5601 57356 Cp949
ksc 57356 Cp949
ujis 57351 EUC_JP
gb 57357 ISO2022CN_GB
GB2312-80 57357 ISO2022CN_GB
cp936 57357 ISO2022CN_GB

You cannot use an Informix locale with a code set where there is no JDK supported encoding. This incorrect usage results in an Encoding not supported error message.

If the connection is made but the database server returns a warning of a mismatch between the DB_LOCALE value sent and the real value in the database systables catalog, the correct database locale is automatically extracted from the systables catalog and the client uses the correct JDK encoding for the connection.

The following table shows the supported locales.

Supported Locales
ar_ae ar_bh ar_kw ar_om ar_qa
ar_sa bg_bg ca_es cs_cz da_dk
de_at de_ch de_de el_gr en_au
en_ca en_gb en_ie en_nz en_us
es_ar es_bo es_cl es_co es_cr
es_ec es_es es_gt es_mx es_pa
es_pe es_py es_sv es_uy es_ve
fi_fi fr_be fr_ca fr_ch fr_fr
hr_hr hu_hu is_is it_ch it_it
iw_il ja_jp ko_kr mk_mk nl_be
nl_nl no_no pl_pl pt_br pt_pt
ro_ro ru_ru sh_yu sk_sk sv_se
th_th tr_tr uk_ua zh_cn zh_tw

Unicode to Client Code Set

Because the Unicode code set includes all existing code sets, the Java virtual machine (JVM) must render the character using the platform's local code set. Inside the Java program, you must always use Unicode characters. The JVM on that platform converts input and output between Unicode and the local code set. For example, you specify button labels in Unicode, and the JVM converts the text to display the label correctly. Similarly, when the getText() method gets user input from a text box, the client program gets the string in Unicode, no matter how the user entered it.

Never read a text file one byte at a time. Always use the InputStreamReader() or OutputStreamWriter() methods to manipulate text files. By default, these methods use the local encoding, but you can specify an encoding in the constructor of the class, as follows:

You and the JVM are responsible for getting external input into the correct Java Unicode string. Thereafter, the database locale encoding is used to send the data to and from the database server.

Connecting to a Database with Non-ASCII Characters

If you do not specify the database name at connection time, the connection must be opened with the correct DB_LOCALE value for the specified database.

If close database and database dbname statements are issued, the connection continues to use the original DB_LOCALE value to interpret the database name, so if the DB_LOCALE value of the new database does not match, an error is returned. In this case, the client program must close and reopen the connection with the correct DB_LOCALE value for the new database.

If you supply the database name at connection time, the DB_LOCALE value must be set to the correct database locale.

Code Set Conversion for TEXT Data Types

Informix JDBC Driver does not automatically convert between code sets for TEXT, BYTE, CLOB, and BLOB data types. You can convert between code sets for TEXT data by using the getBytes(), getString(), InputStreamReader(), and OutputStreamWriter() methods. These methods take a code set parameter that converts to and from Unicode and the specified code set. These methods are covered in detail in Sun's JDK documentation.

Here is sample code that shows how to convert a file from the client code set to Unicode and then from Unicode to the database code set. When you retrieve data from the database, you can use the same approach to convert the data from the database code set to the client code set.


Informix JDBC Driver Programmer's Guide, Version 2.0
Copyright © 1999, Informix Software, Inc. All rights reserved