Skip Headers

Oracle® Database JDBC Developer's Guide and Reference
10g Release 1 (10.1)

Part Number B10979-02
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Feedback

Go to previous page
Previous
Go to next page
Next
View PDF

12 Globalization Support

Oracle's JDBC drivers provide Globalization Support (formerly NLS). Globalization Support allows you retrieve data or insert data into a database in any character set that Oracle supports. If the clients and the server use different character sets, then the driver provides the support to perform the conversions between the database character set and the client character set.

This chapter contains the following sections:

For more information on Globalization Support, Globalization Support environment variables, and the character sets that Oracle supports, see "Oracle Character Datatypes Support" and the Oracle Database Globalization Support Guide. See the Oracle Database Reference for more information on the database character set and how it is created.


Notes:

  • As of 10g Release 1 (10.1), the NLS_LANG variable is no longer part of the JDBC globalization mechanism; setting it has no effect.

  • The JDBC Server-side Internal driver provides complete globalization support, and does not require any globalization extension files. You can skip this chapter if you only use the Server-side Internal driver.

12.1 Providing Globalization Support

The basic JAR files (classes12.jar and ojdbc14.jar) contain all the necessary classes to provide complete globalization support for:

To use any other character sets in CHAR or VARCHAR data members of Objects or Collections, you must include orai18n.jar in your application's CLASSPATH.


Note:

Previous releases depended on the file nls_charset12.zip; this file is now obsolete.

12.1.1 Compressing ora18n.jar

The file orai18n.jar contains many important character set and globalization support files. You can reduce the size of orai18n.jar by including only the character set classes you use in your application

The character set extension class files are located in oracle/i18n/data/ and named in the format lx20OracleCharacterSetId.glb, where OracleCharacterSetId is the hexadecimal representation of the Oracle character set ID. You can determine the decimal representation of any ID by using the SQL function NLS_CHARSET_ID.

For example, if your application connects to a JA16SJIS database, the following SQL statement returns the decimal representation of that character set:

select NLS_CHARASET_ID('ja16sjis') from DUAL;

The example returns 832. You would then manually convert this decimal value to hexadecimal, getting 340. This means that the character set extension class file corresponding to JA16SJIS would be oracle/i18n/data/lx20340.glb.

You can reduce the size of orai18n.jar by including only the character set classes you use in your application. To do so, use the following steps:

  1. Unpack orai18n.jar into a temporary directory.

  2. Delete all files in your temporary directory except the lx20OracleCharacterSetId.glb files that your application uses and the following 18 class files:

    • oracle/i18n/util/ClassLoaderChooser.class

    • oracle/i18n/util/ConverterArchive.class

    • oracle/i18n/util/GDKMessage.class

    • oracle/i18n/util/GDKOracleMetaData.class

    • oracle/i18n/util/OraClassLoader.class

    • oracle/i18n/util/OraResourceBundle.class

    • oracle/i18n/util/message/Messages.class

    • oracle/i18n/text/converter/CharacterConverter12Byte.class

    • oracle/i18n/text/converter/CharacterConverterOGS.class

    • oracle/i18n/text/converter/CharacterConverter1Byte.class

    • oracle/i18n/text/converter/CharacterConverterGB18030.class

    • oracle/i18n/text/converter/CharacterConverterJAEUC.class

    • oracle/i18n/text/converter/CharacterConverterLC.class

    • oracle/i18n/text/converter/CharacterConverterLCFixed.class

    • oracle/i18n/text/converter/CharacterConverterZHTEUC.class

    • oracle/i18n/text/converter/CharacterConverter2ByteFixed.class

    • oracle/i18n/text/converter/CharacterConverterSJIS.class

    • oracle/i18n/text/converter/CharacterConverterShift.class

  3. Make sure that your temporary directory has the same directory structure as the original package. The class files and glb files should be in the following directories:

    • oracle/i18n/data/OracleCharacterSetId.glb files

    • oracle/i18n/util/—6 class files

    • oracle/i18n/util/message/—1 class file

    • oracle/i18n/text/converter/—11 class files

  4. Using a different filename than the original orai18n.jar, create a JAR file from the temporary directory and add the JAR file to your CLASSPATH.

You can also include internationalized JDBC error message files selectively. The message files are included in classes*.* under the name oracle/jdbc/driver/Messages_*.properties.

12.2 NCHAR, NVARCHAR2, NCLOB and the defaultNChar Property

By default, oracle.jdbc.OraclePreparedStatement treats all columns as CHAR. To insert Java strings into NCHAR, NVARCHAR2, and NCLOB columns, developers had to invoke setFormOfUse() on each national-language column. At this release, if you set the system property oracle.jdbc.defaultNChar to true, JDBC treats all character columns as being national-language. The default value for defaultNChar is false.

To set defaultNChar, you specify a command line like:

java -Doracle.jdbc.defaultNChar=true myApplication

If you prefer, your application can specify defaultNChar as a connection property.

After this property is set, your application can access NCHAR, NVARCHAR2, or NCLOB data without invoking setFormOfUse(). For example:

PreparedStatement pstmt =
conn.prepareStatement("insert into TEST values(?,?,?)");
pstmt.setInt(1, 1); // NUMBER column
pstmt.setString(2, myUnicodeString1); // NVARCHAR2 column
pstmt.setString(3, myUnicodeString2); // NCHAR column
pstmt.execute();

However, if you set defaultNChar to true and then access CHAR columns, the database will implicitly convert all CHAR data into NCHAR. This conversion has a substantial performance impact. To avoid this, call setFormOfUse(4,OraclePreparedStatement.FORM_CHAR) for each CHAR referred to in the statement. For example:

PreparedStatement pstmt =
conn.prepareStatement("insert into TEST values(?,?,?)");
pstmt.setInt(1, 1); // NUMBER column
pstmt.setString(2, myUnicodeString1); // NVARCHAR2 column
pstmt.setString(3, myUnicodeString2); // NCHAR column
pstmt.setFormOfUse(4, OraclePreparedStatement.FORM_CHAR);
pstmt.setString(4, myString); // CHAR column
pstmt.execute();

12.3 JDBC Methods Dependent On Conversion

Here are a few examples of commonly used Java methods for JDBC that rely heavily on character set conversion: