0

I have mysql server 8.0.21 with configuration

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

And a table with charset utf8mb4

CREATE TABLE `test` (`c0` TEXT) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

This code is working with mysql-connector-java 5.1.18

Connection conn = DriverManager.getConnection("jdbc:mysql://hostxxxx/test?" +
        "user=userxxx&password=passxxx");
String sql = "INSERT INTO test(c0) value ('')"; 
conn.createStatement().execute(sql)

But when I use mysql-connector-java-5.1.44 (or higher) -> get the error java.io.IOException: Incorrect string value: '\xF0\x9F\x9A\x98\xF0\x9F...'

I am able to get this code to work with version 5.1.44++ by changing the server config character_set_server to utf8mb4, But because backward compatible, I could not change it

Anyone know how this code working with the old version (mysql-connector-java-5.1.18) but not work with the version (5.1.44 and later) I found some related topics to this error but could not resolve my issue

4

0 回答 0