Reputation: 1809
I have a system which previously used:
And I was able to save and read emojis to/from that table column using java.
The mysql connector has now been upgraded to 8.0.12 for some reason, and the system complains when saving emojis,
Caused by: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x90\x91' for column 'name' at row 1
Anyone have idea how to fix this? Many thanks.
BTW, the JDBC connection string I'm using already has useUnicode=true and characterEncoding=UTF-8
Upvotes: 0
Views: 246
Reputation: 142373
That sheep needs utf8mb4, not utf8 throughout MySQL. Not just the column, but also the connection.
For Java:
Add ?useUnicode=yes&characterEncoding=UTF-8
to the JDBC URL (or maybe it is =true and =utf8)
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=UTF-8" %>
compileJava.options.encoding = 'UTF-8'
<form method="post" action="/your/url/" accept-charset="UTF-8">
To use 4-byte UTF8 with Connector/J configure the MySQL server with character_set_server=utf8mb4
. Connector/J will then use that setting as long as characterEncoding has not been set in the connection string. This is equivalent to autodetection of the character set.
Upvotes: 1