gpt4 book ai didi

java - 如何在mysql表中保存货币符号unicode

转载 作者:行者123 更新时间:2023-11-28 23:08:55 28 4
gpt4 key购买 nike

我正在使用 mysql 表来存储货币符号 unicode 但是当我将它返回到我的 dto 中的 android 应用程序时,它显示相同的 unicode 字符串(\u20B9)而不是货币符号().

早些时候,我使用它进行硬编码,如 dto.setCurrencyCode("\u20B9"),它工作正常,但如果我从 mysql 表中获取它并在 dto 中设置,它就无法工作。

mysql 表字符集是这样的-

+--------------+--------------+-----------------+------+-----+---------+----------------+---------------------------------+---------+
| Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment |
+--------------+--------------+-----------------+------+-----+---------+----------------+---------------------------------+---------+
| id | bigint(20) | NULL | NO | PRI | NULL | auto_increment | select,insert,update,references | |
| apiUrl | varchar(255) | utf8_general_ci | YES | | NULL | | select,insert,update,references | |
| countryCode | varchar(255) | utf8_general_ci | YES | | NULL | | select,insert,update,references | |
| currencyCode | varchar(255) | utf8_general_ci | YES | | NULL | | select,insert,update,references | |
| locale | varchar(255) | utf8_general_ci | YES | | NULL | | select,insert,update,references | |
| mcc | int(11) | NULL | NO | MUL | NULL | | select,insert,update,references | |
| msisdnLength | int(11) | NULL | NO | | NULL | | select,insert,update,references | |
+--------------+--------------+-----------------+------+-----+---------+----------------+---------------------------------+---------+

表格条目就像-

mysql> select * from MccDetails;
+----+-------------------------------------+-------------+--------------+--------+-----+--------------+
| id | apiUrl | countryCode | currencyCode | locale | mcc | msisdnLength |
+----+-------------------------------------+-------------+--------------+--------+-----+--------------+
| 1 | https://localhost:8080/api/ | +91 | \u20B9 | en | 404 | 10 |
| 2 | https://localhost:8080/api/ | +91 | \u20B9 | en | 405 | 10 |
+----+-------------------------------------+-------------+--------------+--------+-----+--------------+

这是我的连接字符串 -jdbc:mysql://127.0.0.1:3306/dbname?autoReconnect=true&useUni‌ code=true&connection‌ Collat​​ion=utf8_gener‌ al_ci&characterSetRe‌ sults=utf8

请告诉我 currencyCode 列的数据类型应该是什么以及如何在表中存储 unicode 值 (\u20B9) 或者在客户端服务器架构中处理货币符号的最佳方式是什么.

最佳答案

它显然存储为字符串而不是字符。

你所要做的就是像那样对连接字符串启用正确的编码

jdbc:mysql:///dbname?useUnicode=true&characterEncoding=utf-8"

当您执行此操作时,具有 ₹ 等字符的字符串将正确存储到数据库中。您不必再使用\u20B9 代码

关于java - 如何在mysql表中保存货币符号unicode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46482612/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com