简体   繁体   中英

Problem reading special characters from teradata - JDBC

I use teradata and the below query outputs "Altlüd" when run using a teradata client.

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). I am using "UTF-8" charset and I have also tried Latin charset with no luck.

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 = ? 100 = d

If you look at the output produced, the int value for the spl character is 65533 which shouldn't be the case.

Infact it returns 65533 for all the special characters.

Any clues/pointers will be appreciated. Thanks!!!

Try to use CHARSET=UTF-16 as client side parameter.

One easy way is to set LC_ALL = LANG = en_US.UTF-16 and then run your Java program.

Seems to be the Unicode Replacement character U+FFFD . JDBC client and server do not use the same encoding for characters. The client seems to try UTF-8, but the server does offer any non UTF format.

I do not know teradata, but you should look for any database and or server settings for the encoding and/or locale.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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