Reading Arabic text from Oracle database encoded i

2019-08-04 07:39发布

I connect to Oracle database which has NLS_CHARACTERSET (WE8ISO8859P1) , which as far as I know cannot support storing Arabic text.

But Toad for Oracle can read Arabic from this database:

Toad:

However, I cannot read this using java code.

even I tried to get row of them in bytes using UTL_RAW.CAST_TO_RAW

The result was "218,227,237,225,228,199,32,199,225,218,210,237,210,161,225,222,207,32,199,211,202,229,225,223,202,32,32,56,48,37,32,227,228,32,230,205,207,199,202,32,221,225,237,223,211,32,32,32"

In a test java class, I tried to create new String(new char[]{}) using the above mentioned bytes, with no luck to display Arabic characters.

Any help ? , thank you.

1条回答
可以哭但决不认输i
2楼-- · 2019-08-04 08:11

This could be caused by quite a few things:

  1. Check the column type in database it should be NVARCHAR not VARCHAR (notice the "N" at the beginning of the word)

  2. Try to put charset=utf8 in the connection string

  3. Convert the byte[] to string using UTF-8 encoding like this

    String arabicText = new String(byteArray, "UTF-8");
    
查看更多
登录 后发表回答