When we use grails with MySQL the default character encoding is ISO/IEC 8859-1 also called Latin 1. If we want our application to support UTF-8 character encoding then we need to do some configurations.
Following are the simple steps for UTF-8 character encoding in grails application:
-
Changes in Grails:
Open your DataSource.groovy and change url in dataSource like:
123456789...dataSource {driverClassName="com.mysql.jdbc.Driver"url="jdbc:mysql://localhost/myApp?useUnicode=true&characterEncoding=UTF-8"username="my_username"password="my_password"dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''}... -
Changes in MySQL:
Create your database that can support UTF-8 character encoding using the following command in MySQL console:1CREATE DATABASE database_name CHARACTER SET utf8 COLLATE utf8_general_ci;
and that’s all.
Hope this helps 🙂 .
Recent Comments