I am trying to save Russian characters in mysql using the grails application, however in the DB it is stored as ????
Mapping my datasource:
dataSource { pooled = true driverClassName = "com.mysql.jdbc.Driver" dialect = "org.hibernate.dialect.MySQL5InnoDBDialect" username = "sa" password = "" } .... url = "jdbc:mysql://localhost/mydb?useUnicode=true&zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8"
My domain class
class Lang { String langText static constraints = { langText nullable: true, blank: true } static mapping = { langText type: 'text' } }
Coding table lang utf8
mysql> SELECT CCSA.character_set_name FROM information_schema.`TABLES` T, -> information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA -> WHERE CCSA.collation_name = T.table_collation -> AND T.table_name = "lang"; +--------------------+ | character_set_name | +--------------------+ | utf8 | +--------------------+ 1 row in set (0.01 sec)
Encoding for lang_text column is utf8
mysql> SELECT character_set_name FROM information_schema.`COLUMNS` -> WHERE table_name = "lang" -> AND column_name = "lang_text"; +--------------------+ | character_set_name | +--------------------+ | utf8 | +--------------------+ 1 row in set (0.01 sec)
This is how I save the information in the database:
def lang() { Lang l = new Lang() l.langText = ", "; l.save(flush: true) }
But when I look at the database, the information is stored as ?????
mysql> select lang_text from lang where id = (select max(id) from lang); +---------------------------------+ | lang_text | +---------------------------------+ | ????????????, ???? ????? ?????? | +---------------------------------+ 1 row in set (0.00 sec)
This seems to be a GORM / Hibernate problem, because when I enter a row into the database using mysql, it adds a penalty:
mysql> insert into lang (lang_text) values (", "); Query OK, 1 row affected, 1 warning (0.10 sec) mysql> select lang_text from lang where id = (select max(id) from lang); +------------------------------------------------------------+ | lang_text | +------------------------------------------------------------+ | , | +------------------------------------------------------------+ 1 row in set (0.05 sec)