Character encoding in Java applications

Java programs use UNICODE text internally; however, the character data in a DB2 Everyplace table could be in a format other than UNICODE, depending on the operating system and language in which the table was created. For Windows CE and Symbian OS operating systems, the DB2 Everyplace JDBC driver retrieves and inserts text as UTF-8 format. For other supported operating systems, the system's default character encoding is used. The default is usually determined by the "file.encoding" attribute of the Java system property.

For example, on the Win32 operating system, a user might choose to use a UNICODE or non-UNICODE version of the CLI interface; on the same machine, therefore, one database could have UTF-8 format encoding and one local codepage encoding. To enable a JDBC application to access the data from both databases, DB2 Everyplace provides a way for users to dynamically indicate which data encoding format an application should use.

The DB2 Everyplace JDBC driver converts Java strings into bytes according to the format specified by the application. The application-specified format overrides the operating system's default character encoding.

Users can dynamically specify the application's data encoding format through the JDBC interface. To do this:

  1. Create a java.util.Properties object.

    Use the value UTF-8 to specify DB2 Everyplace using UTF-8 coding, or use any character encoding supported by the JVM.

  2. Use one of the following two methods to pass the java.util.properties object:

Zugehörige Referenzen