0


I am trying to persist Arabic characters into Oracle 11g Database. When I persist Arabic strings they persist successfully but, in the database they appear as question marks ???????.

I searched and found that problem might be with database encoding, but I think that might not be true as I am able to write Arabic strings from SQLDeveloper and commit DB, it displays correctly within DB table. Also when I retrieve that field and display it on screen, it displays correctly.

So from this I concluded that DB recognizes Arabic and there is no problem there. I tried setting Client/Server region language settings still did not fix the problem. After reading this post and trying its suggestions, I found that problem might be with persistence layer, that it does not handle Arabic characters properly. What is the solution to this?

I am not sure if this is a redundant question but I am desperate. Any help/advice is appreciated.

Systems I am using:
Server: Oracle Thin 11g
IDE: IBM WebSphere Integration Developer with JSF 1.2
Note: Still a beginner.

EDIT

Insert code:

       String a = "اشتغل";
       byte[] b = a.getBytes("UTF-8");
       String c = new String(b,"UTF-8");
       localLgInst.setBdStatus(c);
       System.out.println("status " + localLgInst.getBdStatus()); 
       entityManager.persist(localLgInst);
       entityManager.flush();

localLgInst is an instance of an entity. Currently I am putting the string hard coded. System out prints the string in console of IDE but also ???????.

Community
  • 1
  • 1

2 Answers2

0

Try to write arabic text to NVARCHAR column

Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275
0

One POSSIBLE error is that unicode is lost somewhere in your code. You must support Unicode / UTF8 from the string creation to the saving of the string in the database.

Arabic characters should be contained in UTF8 characterset, no need to use UTF16

Use bytes to support UTF8, String object don't have an encoding. See an explanation here: https://stackoverflow.com/a/5729834/891479

For String/bytes UTF8 handling you can have a look there: https://stackoverflow.com/a/88863/891479

If you want to go deeper in the topic: http://www.oracle.com/us/technologies/java/supplementary-142654.html

Community
  • 1
  • 1
L. G.
  • 9,642
  • 7
  • 56
  • 78
  • Ok so here is what I tested.. I set my string : String a = "شنتينشستانتشساي"; Converted to byte[]: byte[] b = a.getBytes("UTF-8"); Then changed the bytes back to UTF-8: String c = new String(b, "UTF-8"); This way I ensure that the string was converted from bytes using UTF-8. Still ????? in DB.. Also tested byte to string conversion with Windows-1252(gave foreign letters) , US-ASCII (gave ???), Windows-1256(gave foreign letters) P.S. this string is an attribute in an entity? Should i change something within the entity? – Murtaza Shehabi Aug 27 '13 at 11:08
  • If you save in DB directly after creating the string this is probably not the problem. Could you update your question and provide us the code you use to save your string in DB? What client do you use to see the content of the field? Is your client Unicode compatible? Did you try to read back the field to ensure it not only a display problem? – L. G. Aug 27 '13 at 11:41
  • I have edited the code above. please check if there is anything I am doing wrong. – Murtaza Shehabi Aug 28 '13 at 08:19
  • Do your DB support unicode? See http://docs.oracle.com/cd/B28359_01/server.111/b28298/ch6unicode.htm – L. G. Aug 28 '13 at 16:17