已经使用utf8mb4但得到1366:字符串值不正确:'\ xF0 \ x9F \ x98 \ x81 \ xF0 \ x9F ......'

时间:2016-12-05 14:28:12

标签: java mysql jdbc encoding character-encoding

问题的所有答案“字符串值不正确”指向使用utf8mb4。但是,我仍在使用它仍然会出现错误。

运行

SELECT CCSA.character_set_name, collation_name FROM information_schema.`TABLES` T,
       information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
WHERE CCSA.collation_name = T.table_collation
  AND T.table_schema = "test"
  AND T.table_name = "products";

产生

character_set_name  collation_name
utf8mb4             utf8mb4_unicode_ci

正在运行

SELECT character_set_name, collation_name FROM information_schema.`COLUMNS` 
WHERE table_schema = "test"
  AND table_name = "products"
  AND column_name = "description";

产生相同的结果。然后,当我尝试更新列description时: 更新testproducts SET description ='Esperienza molto negativa ... SCONSIGLIATISSIMO'WHER id ='50'

我得到了上述错误

1366: Incorrect string value: '\xF0\x9F\x98\x81\xF0\x9F...' for column 'description' at row 1

我已经通过jdbc连接jdbc:mysql://localhost:3306/test?useUnicode=yes;characterEncoding=utf8;和直接通过MySQLWorkbench尝试了此更新。我不知道还有什么可以寻找的。我错过了什么?

修改 输出SHOW CREATE TABLE

CREATE TABLE `products` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `manufacturerId_fk` int(11) NOT NULL,
  `type_fk` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'TEST',
  `ownerId_fk` int(11) DEFAULT NULL,
  `rating_fk` int(11) NOT NULL,
  `description` varchar(2000) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `authorName` varchar(75) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `authorUrl` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `manufacturer_authorUrl_UNIQUE` (`manufacturerId_fk`,`authorUrl`),
  KEY `fk_products_manufacturers_idx` (`manufacturerId_fk`),
  KEY `fk_products_users_idx` (`ownerId_fk`),
  KEY `fk_products_validRatings_idx` (`rating_fk`),
  KEY `fk_products_productTypes` (`type_fk`),
  CONSTRAINT `fk_products_productTypes` FOREIGN KEY (`type_fk`) REFERENCES `productTypes` (`type`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_products_manufacturers` FOREIGN KEY (`manufacturerId_fk`) REFERENCES `manufacturers` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_products_validRatings` FOREIGN KEY (`rating_fk`) REFERENCES `validRatings` (`value`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=418 DEFAULT CHARSET=utf8mb4

1 个答案:

答案 0 :(得分:0)

类似的问题出现在我的文本字段中。 (MySQL 1366错误,字符串值不正确)

我确认数据库,表,列的字符集均为utf8mb4

通过将文件类型更改为longtext解决了问题。

希望这可以帮助某人。