How to set useUnicode=true and characterEncoding=utf8 properties on Spring-managed MySQL JDBC connection

后端 未结 5 658
醉话见心
醉话见心 2021-02-05 06:27

I\'m currently building a Spring MVC webapp and the database is the vital backend part. For whatever reason, however, Spring is refusing to process the data as UTF-8. Since the

5条回答
  •  你的背包
    2021-02-05 06:55

    I had the same issue while using Spring-boot + embedded H2 + Hibernate, but the problem was at the moment of reading SQL script. (data.sql) The encoding in the database was broken every time when I it read any foreign character.

    Adding the following line to my application.properties solved the problem:

    spring.datasource.sqlScriptEncoding=UTF-8

    If it is possible go to the console and add some data manually. If the foreign characters appear in the right way. Then this solution may work fine for you.

    I have found that solution here:

    http://ufasoli.blogspot.com/2014/07/spring-boot-jpa-broken-encoding-on.html

提交回复
热议问题