简体   繁体   English

从 teradata 读取特殊字符时出现问题 - JDBC

[英]Problem reading special characters from teradata - JDBC

I use teradata and the below query outputs "Altlüd" when run using a teradata client.当使用 teradata 客户端运行时,我使用 teradata 和以下查询输出“Altlüd”。

select name as name  from MYTABLE where selector=?

Whereas, I get "Altl?d" as the output when I try to execute the query using a java client(jdbc with teradata drivers).然而,当我尝试使用 java 客户端(带有 teradata 驱动程序的 jdbc)执行查询时,我得到“Altl?d”作为输出。 I am using "UTF-8" charset and I have also tried Latin charset with no luck.我正在使用“UTF-8”字符集,我也尝试过拉丁字符集但没有成功。

I have also tried this to troubleshoot.我也试过这个来排除故障。

while (rs.next()) {
 System.out.println(rs.getString(1));
 Reader rd = rs.getCharacterStream(1);
 int charr = rd.read();
 while (charr >= 0) {
    System.out.println(charr + " = " + ((char) charr));
    charr = rd.read();
 }
}

And the output is输出是

Altl?dersdorf 65 = A 108 = l 116 = t 108 = l 65533 = ? Altl?dersdorf 65 = A 108 = l 116 = t 108 = l 65533 = ? 100 = d 100 = d

If you look at the output produced, the int value for the spl character is 65533 which shouldn't be the case.如果您查看生成的输出,则 spl 字符的 int 值是 65533,这不应该是这种情况。

Infact it returns 65533 for all the special characters.事实上,它为所有特殊字符返回 65533。

Any clues/pointers will be appreciated.任何线索/指针将不胜感激。 Thanks!!!谢谢!!!

Try to use CHARSET=UTF-16 as client side parameter.尝试使用 CHARSET=UTF-16 作为客户端参数。

One easy way is to set LC_ALL = LANG = en_US.UTF-16 and then run your Java program.一种简单的方法是设置LC_ALL = LANG = en_US.UTF-16 ,然后运行您的 Java 程序。

Seems to be the Unicode Replacement character U+FFFD .似乎是 Unicode 替换字符U+FFFD JDBC client and server do not use the same encoding for characters. JDBC 客户端和服务器不对字符使用相同的编码。 The client seems to try UTF-8, but the server does offer any non UTF format.客户端似乎尝试使用 UTF-8,但服务器确实提供任何非 UTF 格式。

I do not know teradata, but you should look for any database and or server settings for the encoding and/or locale.我不知道 teradata,但您应该查找编码和/或语言环境的任何数据库和/或服务器设置。

使用 CHARSET=UTF16 而不是 CHARSET=UTF-16,可以找到更多信息https://docs.teradata.com/reader/pk_W2JQRhJlg28QI7p0n8Q/tE40Yeyi9_0_~khKoRUbFA

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

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