I need to be able to store characters like \\xF0\\x9F\\x94\\xA5
in my database, which, according to this post need UTF8mb4
encoding.
So I
You do not need any change in the Java side, as utf8mb4
is just UTF-8
in Java.
Instead, as you can see here:
show variables WHERE variable_name like "col%";
+----------------------+------------------+
| Variable_name | Value |
+----------------------+------------------+
| collation_connection | utf8_general_ci |
| collation_database | utf32_general_ci |
| collation_server | utf8_general_ci |
+----------------------+------------------+
your connection setting is still utf8_general_ci
; to set it at the connection level, one option is to execute the (mysql specific) query:
SET NAMES='utf8mb4'
before any attempt to use the utf8mb4 collation; or, generally for the mysql server, in /etc/my.cnf
:
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
Another option without changing the connection string, is using a jdbc driver version >= 5.1.13: http://www.opensubscriber.com/message/java@lists.mysql.com/14151747.html