How do I set character encoding for Oracle 10g with JDBC

19,194

Solution 1

The data transferred by the thin Oracle JDBC driver is always sent as UTF-16 (java's internal representation). The database server will translate that into whatever national character set it has been configured to use (so if the database was set up to be UTF-8, this conversion will happen automatically). Note that the character set is set at the Database level, not at the schema or connection level.

To find out the character set configured on the DB, execute this query:

SELECT value$ FROM sys.props$ WHERE name = 'NLS_CHARACTERSET' ;

(the account you're using to connect to the db will need to have the proper permissions to read system tables to do this)

Solution 2

I'm not sure I understand the question.

The Oracle database character set is set when the database is created and is quite painful, in general, to change. Your Java application is not going to be able to specify the database character set. You can see what the database and national character set are

SELECT *
  FROM v$nls_parameters
 WHERE parameter LIKE '%CHARACTERSET'

Since your current database character set is ISO 8859-1, it will not be able to store characters from Asian languages. You can follow the instructions on character set migration in the 10g Globalization Support Guide to change the database character set of your existing database. You'll need to work with the DBA to do this since it's going to affect the entire database.

Internally, Java strings are always Unicode (UTF-16 in particular) so there is not much you can do to configure that. The output of your Java application may not be Unicode-- if your Java application is, for example, generating a web site, there is a good possibility that the web pages that are generated are using some non-Unicode character set. But I don't think that's what you're asking about.

Share:
19,194
Admin
Author by

Admin

Updated on June 11, 2022

Comments

  • Admin
    Admin almost 2 years

    I am using Java and Oracle 10g database.

    How can I specify the character encoding like UTF-8 for the Oracle database with JDBC?
    And how can I find out the current encoding used by JDBC?