简体   繁体   English

在Oracle和Java中获取UTF-8字符问题

[英]Geting UTF-8 character issue in Oracle and Java

Have one table in Oracle which contains column type is NVARCHAR2 . 在Oracle中有一个包含列类型的表是NVARCHAR2 In this column I am trying to save Russian characters. 在本专栏中,我试图保存俄语字符。 But it showing ¿¿¿¿¿¿¿¿¿¿¿ like this. 但它显示像这样的¿¿¿¿¿¿¿¿¿¿¿ When I try to fetch same characters from Java, I am getting same string. 当我尝试从Java中获取相同的字符时,我得到相同的字符串。

I have try with NCHAR VARCHAR2 . 我试过NCHAR VARCHAR2 But in all cases same issue. 但在所有情况下同样的问题。

Is this problem from Java or Oracle? 这是Java或Oracle的问题吗? I have try same Java code, same characters using PostgreSQL which is working fine. 我尝试使用相同的Java代码,使用PostgreSQL的相同字符工作正常。 I am not getting whether this problem is from Oracle or Java? 我不知道这个问题是来自Oracle还是Java?

In my oracle database NLS_NCHAR_CHARACTERSET property value is AL16UTF16 . 在我的oracle数据库中, NLS_NCHAR_CHARACTERSET属性值为AL16UTF16 Any Idea how can I show UTF-8 characters as it is in Java which saved in Oracle. 任何想法如何显示在Java中保存在Oracle中的UTF-8字符。

Problem with characters is that you cannot trust your eyes. 角色的问题是你不能相信你的眼睛。 Maybe the database stores the correct character values but your viewing tool does not understand them. 也许数据库存储正确的字符值,但您的查看工具不理解它们。 Or maybe the characters get converted somewhere along the way due to language settings. 或者由于语言设置,角色可能会在途中被转换。

To find out what character values are stored in your table use the dump function: 要找出表中存储的字符值,请使用dump函数:

Example: 例:

select dump(mycolumn),mycolumn from mytable;

This will give you the byte values of your data and you can check whether or not the values in your table are as they should be. 这将为您提供数据的字节值,您可以检查表中的值是否与它们应该的一样。

After doing some google I have resolved my issue. 做了一些谷歌我已经解决了我的问题。 Here is ans: AL32UTF8 is the Oracle Database character set that is appropriate for XMLType data. It is equivalent to the IANA registered standard UTF-8 encoding, which supports all valid XML characters. 这是ans: AL32UTF8 is the Oracle Database character set that is appropriate for XMLType data. It is equivalent to the IANA registered standard UTF-8 encoding, which supports all valid XML characters. AL32UTF8 is the Oracle Database character set that is appropriate for XMLType data. It is equivalent to the IANA registered standard UTF-8 encoding, which supports all valid XML characters.

It means while creating database in Oracle, set AL32UTF8 character set. 这意味着在Oracle中创建数据库时,请设置AL32UTF8字符集。

Here is link for this 这是链接

http://docs.oracle.com/cd/B19306_01/server.102/b14231/create.htm#i1008322 http://docs.oracle.com/cd/B19306_01/server.102/b14231/create.htm#i1008322

You need to specify useUnicode=true&characterEncoding=UTF-8 while getting the connection from the database. 在从数据库获取连接时,需要指定useUnicode=true&characterEncoding=UTF-8 Also make sure the column supports UTF-8 encoding. 还要确保该列支持UTF-8编码。 Go through Oracle documentation . 浏览Oracle文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM