简体   繁体   中英

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

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?

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM