我正在尝试使用grails应用程序将俄语字符保存到mysql中,但是,在数据库中将其存储为????
我的数据源映射:

 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"

我的网域类(class)
class Lang {

    String langText

    static constraints = {
        langText nullable: true, blank: true
    }

    static mapping = {
        langText type: 'text'
    }
}
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)

lang_text的编码为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)

这就是我将信息保存到数据库的方式:
def lang() {
    Lang l = new Lang()
    l.langText = "Здравствуйте, меня зовут Энтони";
    l.save(flush: true)
}

但是当我查看数据库时,信息被存储为?????
mysql> select lang_text from lang where id = (select max(id) from lang);
+---------------------------------+
| lang_text                       |
+---------------------------------+
| ????????????, ???? ????? ?????? |
+---------------------------------+
1 row in set (0.00 sec)

这似乎是一个GORM /休眠问题,因为当我使用mysql将字符串输入数据库时​​,它可以很好地实现:
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)

最佳答案

我能够解决此问题。我的jdbc网址中有&。应该是&
希望这可以节省我在此花费的时间> _ <

07-24 09:45