Taz
Taz

Reputation: 65

How to insert Chinese characters in Oracle DB using Java

I need to insert Chinese characters inside Oracle Data base using Java (hibernate 3.0 /jpa), I tried many methods and failed.

When I persist the entity I see (??? ) in the filed and when I retrieve the value I see the same result.

My Oracle NLS_DATABASE_PARAMETERS:

NLS_CHARACTERSET   WE8MSWIN1252
NLS_NCHAR_CHARACTERSET  AL16UTF16 

The column type is Nvarchar. I set this properties in persistence.xml

<property name="hibernate.connection.useUnicode" value="true"  />
<property name="hibernate.connection.characterEncoding" value="UTF-8"/>
<property name="hibernate.connection.charSet" value="UTF-8"/>

Upvotes: 1

Views: 3198

Answers (2)

Codo
Codo

Reputation: 78795

If you have the chance, then convert your database from the character set WE8MSWIN1252 to AL32UTF8 (which is the default for new Oracle installations). Then all your problems will be gone and you don't need to use problematic data types like NCHAR or NVARCHAR or any special connnection settings.

Upvotes: 2

Rajat Saini
Rajat Saini

Reputation: 557

I had the same problem in SQL server and there we solved it by converting all the varchar fields to nvarchar. Also all the corresponding store procedures and return types need to be changed. Make sure all you procedures also have nvarchar datatype

Upvotes: 1

Related Questions