Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Russian characters being stored as ???? in mysql in grails application

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)
like image 824
Anthony Avatar asked Nov 08 '22 21:11

Anthony


1 Answers

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 >_<

like image 187
Anthony Avatar answered Nov 15 '22 07:11

Anthony