gpt4 book ai didi

java - utf8_unicode_ci 字符串插入错误?

转载 作者:可可西里 更新时间:2023-11-01 08:24:10 24 4
gpt4 key购买 nike

我有 Java 应用程序,通过它我可以对 MySQL 数据库执行不同的操作。问题是插入 utf8 String 时插入不正确。数据库的字符集是utf8,我将排序规则设置为utf8_unicode_ci。服务器连接排序规则也是 utf8_unicode_ci。此外,当我从 phpMyAdmin 插入数据时,它被正确插入,但是当我使用 JOOQ 从 Java 应用程序插入数据时 - 它不是。示例:

Result<ExecutorsRecord> executorsRecord =
context.insertInto(EXECUTORS, EXECUTORS.ID, EXECUTORS.NAME, EXECUTORS.SURNAME, EXECUTORS.REGION, EXECUTORS.PHONE, EXECUTORS.POINTS, EXECUTORS.E_TYPE)
.values(id, name, surname, region, phone, 0, type)
.returning(EXECUTORS.ID)
.fetch();

其中 name = "Бобр"surname = "Добр",生成元组 ????作为名字和????作为姓氏。我检查了两个字符串,它们正确地传递给了方法。

最佳答案

正如@spencer7593 所说,问题可能出在 JDBC 连接器中。所以我在连接的 url 中添加了以下内容:?characterEncoding=utf8 这样最终的 url 就是 "jdbc:mysql://localhost:3306/mydb?characterEncoding= utf8",其中 mydb 是数据库的名称。这解决了我的问题。另外,我想添加以下声明(同样来自@spencer7593):

When we've got things configured correctly, and things aren't working, our goto suspect is the JDBC driver. To get timezone differences between the JVM and the MySQL database sorted out, to prevent the JDBC driver from "helping" by doing an illogical combination of various operations, we had to add two extra obscurely documented settings to the connection string.

进一步reading

关于java - utf8_unicode_ci 字符串插入错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50127875/

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