5

I'm using Spring boot and I can't store emojis in database. I don't have access to my.cnf file. What I've done so far is:

ALTER DATABASE name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;

For each table:
ALTER TABLE table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

For each column:
ALTER TABLE table CHANGE column column VARCHAR(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

In application.properties file I'm using this:

spring.datasource.url = jdbc:mysql://server/database?useUnicode=yes&characterEncoding=UTF-8

And now, when I'm using Postman to send anything with emoji, I see two question marks (??) in database instead emoji. But when I've added something with emoji using phpmyadmin - I see emojis.

Emoji in MySQL

foxbuur
  • 169
  • 1
  • 9
  • utf8 is not the same as utf8mb4 - at least not in MySQL. You use utf8 in the jdbc connection string. – Shadow Apr 26 '17 at 09:19
  • I changed it to utf8mb4 and now I have exception `java.sql.SQLException: Unsupported character encoding 'utf8mb4'.` – foxbuur Apr 26 '17 at 09:47
  • Out of interest, how does Spring Boot and Postman relate to you inserting data in a MySQL table. Is there some application stack you aren't telling us about (e.g. Spring data rest) ? – PaulNUK Apr 26 '17 at 13:28
  • Yes, I'm using Spring to make rest api – foxbuur Apr 26 '17 at 14:13
  • See question marks in http://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored – Rick James Apr 29 '17 at 19:43

0 Answers0