2

We have an Oracle DB using UTF-8 (NLS_CHARACTERSET = AL32UTF8). We then have a J2EE application in Glassfish which uses Hibernate.

While using SQL Plus or SQL Developer we can read and write the data correctly but we are not able to get special characters programmatically.

Reading an ä we get √§

Looking at similar questions I tried:

  • tuning Hibernate properties

    <property name="hibernate.connection.characterEncoding" value="utf8" />
    

  • adding the defaultNChar=true connection property in Glassfish

  • adding the defaultNChar connection property through Hibernate

    <property name="hibernate.connection.defaultNChar" value = "true"/>
    
  • setting the charset to utf8

    <property name="hibernate.connection.charSet" value="utf8" />
    

But I'm still not able to get any character which is not basic ASCII.

Any hint on what am I doing wrong?

Edit: with get I mean fetch with a select statement. Checking with a debugger or comparing with the correct (e.g., "ä") string with an assertion.

5
  • Can you define "get"? Are you not able to view the characters or are you unable to select them from the database? Commented Feb 5, 2012 at 17:41
  • @Ben: you are right: I edited the question clarifying. selecting the value and checking it programmatically or with a debugger. Commented Feb 5, 2012 at 19:08
  • @Matteo is the data in nvarchar fields? Commented Feb 6, 2012 at 20:12
  • No, varchar but I can't change the DB Commented Feb 6, 2012 at 20:37
  • OK, I just saw that the problem is not in the DB connection but in my test string to ch (I forgot the -encoding option in javac) Commented Feb 8, 2012 at 6:52

3 Answers 3

2

As discussed in the comments to the original question using NVARCAR and the following line added to the Hibernate configuration file seems to work.

<property name="hibernate.connection.defaultNChar">true</property>

It did for me.

Sign up to request clarification or add additional context in comments.

Comments

0
+50

You haven't said anything about your connection url from the datasource declaration. Did you try to set the encoding on the connection url?

jdbc:mysql://localhost:3306/yourDB?useUnicode=true&characterEncoding=UTF-8

I can't test for oracle, but for mysql it solves the problem.

1 Comment

The encoding in the URL is MySQL specific. Oracle JDBC driver doe not allow it (URL format: jdbc:oracle:thin:@//[HOST][:PORT]/SERVICE).
0

As stated in the comments I realized that the question does not make sense since there actually is no problem in the DB connection. As suggested in a meta-discussion I am explaining this as an answer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.