使用java从以WE8ISO8859P1编码的Oracle数据库中读取阿拉伯语文本 [英] Reading Arabic text from Oracle database encoded in WE8ISO8859P1 using java

查看:39
本文介绍了使用java从以WE8ISO8859P1编码的Oracle数据库中读取阿拉伯语文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我连接到具有 NLS_CHARACTERSET (WE8ISO8859P1) 的 Oracle 数据库,据我所知它不支持存储阿拉伯文本.

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

但是 Toad for Oracle 可以从此数据库中读取阿拉伯语:

But Toad for Oracle can read Arabic from this database:

但是,我无法使用 java 代码读取此内容.

However, I cannot read this using java code.

甚至我尝试使用 UTL_RAW.CAST_TO_RAW 以字节为单位获取它们的行

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

,结果是 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"

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"

在测试 java 类中,我尝试使用上述字节创建 new String(new char[]{}),但没有成功显示阿拉伯字符.

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.

推荐答案

这可能是由很多原因造成的:

This could be caused by quite a few things:

  1. 检查数据库中的列类型应该是NVARCHAR而不是VARCHAR(注意N"在开头的字)

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

尝试将charset=utf8放入连接字符串

使用 UTF-8 编码将 byte[] 转换为字符串

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

String arabicText = new String(byteArray, "UTF-8");

这篇关于使用java从以WE8ISO8859P1编码的Oracle数据库中读取阿拉伯语文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆