![]() |
|
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.
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.
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.
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:
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:
The precedence rules that define how to determine an end-user format for an internal DATE value are listed here:
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.
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.
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.
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.
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.
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.