gpt4 book ai didi

mysql - 列的字符串值不正确

转载 作者:行者123 更新时间:2023-11-29 19:31:11 24 4
gpt4 key购买 nike

我在尝试将应用程序中的条目保存到 mysql 数据库时遇到此错误

Hibernate operation: could not execute statement; uncategorized SQLException for SQL [n/a]; SQL state [HY000]; error code [1366]; Incorrect string value: '\xE2\x80\x8BShe...' for column 'extracted_text' at row 1; nested exception is java.sql.SQLException: Incorrect string value: '\xE2\x80\x8BShe...' for column 'extracted_text' at row 1 at com.some.scanner.RequestService.$tt__handleMessage(RequestService.groovy:67)

我的表创建如下:

CREATE TABLE `request` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`version` bigint(20) NOT NULL,
`doc_hash` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`extracted_text` longtext COLLATE utf8_unicode_ci,
PRIMARY KEY (`id`),
KEY `FK414EF28FD3E87920` (`batch_id`),
) ENGINE=InnoDB AUTO_INCREMENT=20025 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

我的实体映射在 Grails 中非常简单

class Request {
String docHash
String extractedText

static mapping = {
extractedText type: 'text'
}
}

我需要更改编码类型吗?如果是这样,做什么?

最佳答案

设置数据库属性useUnicodecharacterEncoding。这些将直接传递到您的 JDBC 驱动程序:https://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/tomcat/jdbc/pool/PoolConfiguration.html#getDbProperties%28%29

dataSource {
url = 'jdbc:mysql://...'
properties {
dbProperties {
useUnicode=true
characterEncoding='UTF-8'
}
}
}

有关 MySQL Connect 字符集的更多信息(包括 UTF-8 的拼写):http://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-charsets.html

MySQL 特定的配置属性位于 dbProperties 中:http://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html

...除非它们已被主要 dataSource 属性覆盖:http://docs.grails.org/latest/guide/conf.html#dataSource或者位于“额外”属性中:http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html#Common_Attributes

关于mysql - 列的字符串值不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41772436/

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