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

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


The problem may be caused by specifying utf8 and not UTF-8. From Using Character Sets and Unicode:

When specifying character encodings on the client side, use Java-style names. The following table lists MySQL character set names and the corresponding Java-style names...

and utf8 maps to UTF-8. Try the following JDBC URL:

jdbc:mysql://localhost:3306/?useUnicode=yes&characterEncoding=UTF-8


Note that if you are using Spring Boot, you can do this using properties within application.properties instead of having to add extra parameters to your connection strings:

Put this into application.properties:

spring.datasource.connectionProperties=useUnicode=true;characterEncoding=utf-8;


Did you try:

<property name="connectionProperties">    <props>        <prop key="useUnicode">yes</prop>        <prop key="characterEncoding">utf8</prop>    </props></property>

And also: Did you try a simple Java client (console application) that connects to the DB? Does the UTF-8 work in this case?