Spring-Boot, Unable to save Unicode string in MySql using Spring -data JPA

I have my application.propertiesconfigured as follows:

spring.datasource.username = root
spring.datasource.password = root
spring.datasource.url = jdbc:mysql://localhost:3306/dbname?useUnicode=yes&characterEncoding=UTF-8
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = update
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

And in mine pom.xml, I have a property configured as follows:

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <start-class>toyanathapi.Application</start-class>
        <java.version>1.8</java.version>
</properties>

My Entity: @ Entity OpenResifalEntity Class {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String date;
private int rollno;
private String name;
//Constructors and getters/setters 
}

Problem 1: If I use the above setting, I get an exception

java.sql.SQLException: Incorrect string value: '\xE0\xA4\xA7\xE0\xA4\xBE...

Problem 2: If I change the data source URL to this:

spring.datasource.url = jdbc:mysql://localhost:3306/dbname

Unicode in my database is saved as

 29 | 2074-03-04 |        3 | ?????????????? ?????,?????? ??????, ??????????? ????? ? ???? ???? ???? ??????  

enter image description here

How can I save them in mysql as if they are in unicode instead , getting all the unicode data converted to ????????.

+4
3

/etc/mysql/my.cnf .

[mysql]
default-character-set=utf8
[mysqld]
character-set-server=utf8
+1

.

JDBC: MySQL://: 3306/_ useUnicode = & characterEncoding = UTF-8

.

ALTER TABLE tablename CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

:

+3

. " " fooobar.com/questions/26415/....

,

⚈  spring.jpa.properties.hibernate.connection.characterEncoding=utf-8 
⚈  spring.jpa.properties.hibernate.connection.CharSet=utf-8 
⚈  spring.jpa.properties.hibernate.connection.useUnicode=true 
0
source

Source: https://habr.com/ru/post/1679446/


All Articles