Posts

Showing posts from September, 2015

Grails and Hibernate: Saving emoticons ( unicode ) to MYSQL.

Image
We built a  Grails  application that uses a mail plugin, to send and retrieve emails from mail servers. The plugin employed a scheduled job to retrieve and store the emails on a MySql database table. Initially everything worked as specified until recently when I noticed that some mails were not saved to MYSQL. The error message from MYSQL was 'incorrect string value' bla bla bla.... On close examination, I noticed that the troublesome emails contained emoticons (unicode characters). The unicode characters were responsible for my troubles :( The issue I dug through the MySQL documentation and learnt that my MySQL instance was having a hard time accepting those unicode characters because the database encoding was set to "utf-8". Solution To solve the problem required a change of the mysql default encoding from "utf-8" to "utf8mb4" . Note :We used a MySQL version of 5.6.13 but this solution will also apply to MySQL ve