gpt4 book ai didi

java - utf8(阿拉伯语)字符串显示为问号(?)

转载 作者:行者123 更新时间:2023-11-29 09:30:20 28 4
gpt4 key购买 nike

我使用的是 3.8.2 版本,插入新记录时,utf8 字符串在数据库中显示为问号 (?),但它会正确显示旧记录(使用 phpmyadmin 插入)。

这是我如何初始化 MySQLPool

fun init(vertx: Vertx): MySQLPool {
val connectOptions = MySQLConnectOptions()
.setPort(Config.mysqlPort)
.setHost(Config.mysqlHost)
.setDatabase(Config.mysqlDatabase)
.setUser(Config.mysqlUsername)
.setPassword(Config.mysqlPassword)
.setCharset("utf8") // tried utf8mb4 also same result
.setCollation("utf8_general_ci") // also tried utf8mb4_general_ci

val poolOptions = PoolOptions().setMaxSize(Config.maxPoolSize)

return MySQLPool.pool(vertx, connectOptions, poolOptions)
}

mysql变量

character_set_client        = utf8
character_set_connection = utf8
character_set_database = utf8
character_set_filesystem = binary
character_set_results = utf8
character_set_server = utf8mb4
character_set_system = utf8

表格排序

utf8_general_ci

mysql创建表

 CREATE TABLE `news` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Title` text NOT NULL,
`Image` text NOT NULL,
`Link` mediumtext NOT NULL,
`Summery` mediumtext NOT NULL,
`Story` mediumtext NOT NULL,
`Time` timestamp(6) NOT NULL DEFAULT current_timestamp(6) ON UPDATE current_timestamp(6),
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8

谢谢

最佳答案

看来jvm中的默认字符集设置为windows-1252,将其更改为UTF-8解决了它

System.setProperty("file.encoding", "UTF-8")
val charset = Charset::class.java.getDeclaredField("defaultCharset")
charset.isAccessible = true
charset.set(null,null)

setCharset("utf8")setCollat​​ion("utf8_general_ci") 选项是在连接级别配置的,但实际上对编码的字符集没有影响,这就是为什么编码值使用默认的 jvm 字符集进行编码

关于java - utf8(阿拉伯语)字符串显示为问号(?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58856871/

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