java.sql.SQLException: 不正确的字符串值:'\xF3\xBE\x8D\x81'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3377164/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 22:42:51  来源:igfitidea点击:

java.sql.SQLException: Incorrect string value: '\xF3\xBE\x8D\x81'

javamysqlutf-8

提问by sesmic

I am getting the following exception while trying to save some Tweets,

我在尝试保存一些推文时遇到以下异常,

Caused by: java.sql.SQLException: Incorrect string value: '\xF3\xBE\x8D\x81' for column 'twtText' at row 1 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2019) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1937) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1922) at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94) at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57)

引起:java.sql.SQLException:字符串值不正确:com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055) com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)第1行'twtText'列的'\xF3\xBE\x8D\x81' .mysql.jdbc.SQLError.createSQLException(SQLError.java:956) 在 com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491) 在 com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423) 在com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)在 com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734) 在 com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2019) 在 com.mysql.jdbc.PreparedStatement。executeUpdate(PreparedStatement.java:1937) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1922) at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94) at org.hibernate .insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57)

My table structure is given below, all the columns are in UTF-8 format,

我的表结构如下,所有列都是UTF-8格式,

 CREATE TABLE `tblkeywordtracking` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `word` varchar(200) NOT NULL,
  `tweetId` bigint(100) NOT NULL,
  `twtText` varchar(800) DEFAULT NULL,
  `negTwtText` varchar(1000) DEFAULT NULL,
  `language` text,
  `links` text,
  `negWt` double DEFAULT NULL,
  `posWt` double DEFAULT NULL,
  `tweetType` varchar(20) DEFAULT NULL,
  `source` text,
  `sourceStripped` text,
  `isTruncated` varchar(40) CHARACTER SET latin1 DEFAULT NULL,
  `inReplyToStatusId` bigint(30) DEFAULT NULL,
  `inReplyToUserId` int(11) DEFAULT NULL,
  `isFavorited` varchar(40) CHARACTER SET latin1 DEFAULT NULL,
  `inReplyToScreenName` varchar(40) DEFAULT NULL,
  `latitude` bigint(100) NOT NULL,
  `longitude` bigint(100) NOT NULL,
  `retweetedStatus` varchar(40) CHARACTER SET latin1 DEFAULT NULL,
  `statusInReplyToStatusId` bigint(100) NOT NULL,
  `statusInReplyToUserId` bigint(100) NOT NULL,
  `statusFavorited` varchar(40) CHARACTER SET latin1 DEFAULT NULL,
  `statusInReplyToScreenName` text,
  `screenName` text,
  `profilePicUrl` text,
  `twitterId` bigint(100) NOT NULL,
  `name` text,
  `location` text,
  `bio` text,
  `utcOffset` int(11) DEFAULT NULL,
  `timeZone` varchar(100) DEFAULT NULL,
  `frenCnt` bigint(20) DEFAULT '0',
  `createdAt` datetime DEFAULT NULL,
  `createdOnGMT` text CHARACTER SET latin1,
  `createdOnServerTime` datetime DEFAULT NULL,
  `follCnt` bigint(20) DEFAULT '0',
  `favCnt` bigint(20) DEFAULT '0',
  `totStatusCnt` bigint(20) DEFAULT NULL,
  `usrCrtDate` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `id` (`id`,`word`),
  KEY `twtText` (`twtText`(333)),
  KEY `word` (`word`,`tweetType`),
  KEY `posWt` (`posWt`,`negWt`)
) ENGINE=MyISAM AUTO_INCREMENT=1740 DEFAULT CHARSET=utf8;

回答by True Soft

You must add a character set and a collation to column twtText. So your column should look like this:

您必须向 column 添加字符集和排序规则twtText。所以你的专栏应该是这样的:

twtText varchar(800) character set utf8 collate utf8_polish_ci DEFAULT NULL,

Change utf8_polish_ciwith what collation you want.

更改utf8_polish_ci您想要的排序规则。

Run the following query to see the available collations:

运行以下查询以查看可用的排序规则:

SHOW COLLATION;

回答by adamk

It looks like a valid utf-8 sequence, that encodes the following character U+FE341.

它看起来像一个有效的 utf-8 序列,它对以下字符U+FE341 进行编码。

As you can see, this is a Unicode character that uses more than 2 bytes. From thisand thisI deduce that MySQL still doesn't support this subset of Unicode characters (at least for versions < 5.5).

如您所见,这是一个使用超过 2 个字节的 Unicode 字符。从这个这个我推断出 MySQL 仍然不支持这个 Unicode 字符子集(至少对于版本 < 5.5)。

回答by Michael Konietzka

MySQL 5.0/5.1 does not support 4byte UTF8-characters, this is a known limitation. MySQL 5.5 does support 4byte UTF8-characters.

MySQL 5.0/5.1 不支持 4 字节的 UTF8 字符,这是一个已知的限制。MySQL 5.5 支持 4 字节的 UTF8 字符。

See 9.1.10. Unicode Support

9.1.10。Unicode 支持