0

我正在使用 MySQL DB 在 EC2 linux 实例上通过码头运行 java。该列是一个 VARCHAR,设置为接受 utf8mb4 编码。

在玩弄了一些东西之后,我发现当我通过 运行这段代码时它可以工作gradle jettyRunWar,甚至在 tomcat 服务器上运行相同的代码时也是如此。

当我在 $JETTY_HOME/webapps/root.war 中放置与之前完全相同的战争时,它不起作用,然后使用sudo service jetty start.

显示的错误是 -

java.sql.BatchUpdateException: Incorrect string value: '\xF0\x9F\x99\x89' for column 'name' at row 1

当前列定义 -

`name` varchar(50) CHARACTER SET utf8mb4 DEFAULT NULL

值是通过preparedStatement.setString(...) 在SQL 中设置的,我确保mysql 连接器JAR 是相同的。

有任何想法吗?

4

1 回答 1

0

Problem resolved once I've set all character_set_... MySQL DB variables to utf8mb4.

That probably means that newer version of jetty (8+) treat JDBC connection different than Tomcat or than older version, because the exact connection string, beans definition & DB was used at all cases.

Until now, character_set_... params were set to utf8 with specific columns defined as utf8mb4, that used to be enough.

Hopes that saves anyone else the day I was stuck on it.

于 2013-11-14T17:49:32.203 回答