Hibernate + MySQL: How to set the encoding utf-8 for database and tables

后端 未结 9 2192
故里飘歌
故里飘歌 2020-12-13 00:34

My system runs on Linux Mandriva, RDBMS - MySQL 5. I need to have the database and tables created in UTF-8.

Here i

9条回答
  •  没有蜡笔的小新
    2020-12-13 01:12

    Via Spring Java Config dataSource() this should help:

    @Bean
    public DataSource dataSource() {    
        BasicDataSource dataSource = new BasicDataSource();    
        //your username/pass props
        dataSource.setConnectionProperties("useUnicode=true;characterEncoding=utf8;characterSetResults=UTF-8;");
        return dataSource;
    }
    

    Be careful about ';' at the end of properties string!

提交回复
热议问题