-1

I've set the column type to utf8mb4 and the collation to utf8mb4_bin. The table defaults are also utf8mb4 and utf8mb4_bin.

When I use SequelPro to add the emoji "🤖" to the database manually, it works just fine.

However, when I do an INSERT using JDBC, it gives me the Incorrect String Value error.

Here is my connection string: jdbc:mysql://localhost:3306/myschema
I'm using mysql-connector-java-5.1.32-bin.jar

What am I doing wrong?

Here is some of the code I'm using:

String sql = "INSERT INTO table VALUES (?)"
String body = ...;
statement = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
statement.setString(1, body)
statement.execute();
3
  • One thing you're doing wrong is not posting your code. Another one is you post your question on the wrong site.
    – mustaccio
    Mar 5, 2019 at 15:51
  • added some code.
    – satnam
    Mar 5, 2019 at 17:19
  • You also need to connect with utf8mb4: ?useUnicode=yes&characterEncoding=UTF-8
    – Rick James
    Mar 11, 2019 at 22:36

1 Answer 1

1

You probably should upgrade your MySQL Java connector to a later version, best to the one matching your MySQL server. utf8mb4 support was added in version 5.5.3.

Not the answer you're looking for? Browse other questions tagged or ask your own question.