如何使用Java从MySQL数据库中读取保加利亚字符?

时间:2018-02-06 12:04:08

标签: java mysql spring jdbc unicode

在数据库中,我有一个以保加利亚语言存储字符串值的字段。

jdbc.url = JDBC:MySQL的://128.0.0.1:3303 /的databaseName了useUnicode =真安培;的characterEncoding = UTF-8

我的表格定义:

    const crypto = require('crypto');
    const shasum = crypto.createHash('sha1');

    const key = '0b25bb2d-f5dd-4337-9f99-a318196f886a';
    const secret = 'm1aur2Q4FUWWNuMlKq3KKg==';
    const userId = 'sanket';
    const sequence = 0;

    const stringToSign = userId + key + sequence + secret;

    shasum.update(stringToSign);

    const singnature = shasum.digest();
    console.log('Signature ', singnature.toString('base64'));
    const token = singnature.toString('base64').trim();

    console.log(token);

现在,当我在webview上显示值时,数据库中的字符显示为 ??????

在Java控制台上,字符显示为“?????”。

有关如何以正确方式从MySQL读取保加利亚字符串的任何建议吗?

2 个答案:

答案 0 :(得分:1)

utf8 Unicode数据(在您的情况下,保存您的保加利亚语字符的数据)需要utf8 unicode渲染器才能正确显示。

可以将网页设置为渲染utf8。 (https://www.w3.org/International/questions/qa-changing-encoding)。

Workbench很聪明:它在渲染数据时知道列字符集。您的数据存储正确:Workbench的正确渲染就是证据。

听起来你的java控制台并不那么聪明。这很奇怪,因为Java文本字符串内部通常使用Unicode。

答案 1 :(得分:0)

列定义(让我们看SHOW CREATE TABLE)必须是utf8utf8mb4

连接必须指定类似

的客户端编码
⚈  spring.jpa.properties.hibernate.connection.characterEncoding=utf-8
⚈  spring.jpa.properties.hibernate.connection.CharSet=utf-8
⚈  spring.jpa.properties.hibernate.connection.useUnicode=true

更多:请参阅Trouble with UTF-8 characters; what I see is not what I stored

中的“问号”
相关问题