I am trying to save russian characters into mysql using a grails application, however, in the DB it is being stored as ????
My Datasource mapping:
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'
}
}
Encoding of the lang
table is 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 the column lang_text
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 am saving the information to the DB:
def lang() {
Lang l = new Lang()
l.langText = "Здравствуйте, меня зовут Энтони";
l.save(flush: true)
}
But when I look at the database, the information is being 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 the string into the Database using mysql, it adds fine:
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)
I was able to fix this issue. I had &
in my jdbc url. It should have just been &
Hope this saves someone the time I spent on this >_<
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With