How to set UTF-8 encoding in data.sql files for starting H2 data based with Spring?

Asked

Viewed 69 times

0

I have a Spring JPA application with an H2 database. I created a data.sql file with some INSERTS and this script is running normally on application startup, but the special characters are being corrupted when inserted in the tables.

I added in the application.properties the property below but the error still persists

spring.datasource.sqlScriptEncoding=UTF-8

The data is getting in the table this way:

ID      NOME  
1   Afeganist�o
2   �frica do Sul

Same script run manually shows no problem on write.

  • I’ll leave the link of a project I did, take a look at the 4 files and see if it helps you; link_do_project

  • Thanks, I took a look at your files but it didn’t solve my problem.

  • Just to wrap up the topic... I found the reason for the error, the settings were ok, the problem occurred because I was generating the data.sql file in another editor and adding the folder. When opening the file at eclipse I noticed that the data had been corrupted by adding the file to the project folder and not during the recording. I solved the problem by saving the file directly in eclipse.

  • Put what happened as your answer, so other users can see and get an idea of what happened :)

1 answer

0

Just to wrap up the topic... I found the reason for the error, the settings were ok, the problem occurred because I was generating the data.sql file in another editor and adding the folder. When opening the file at eclipse I noticed that the data had been corrupted by adding the file to the project folder and not during the recording. I solved the problem by saving the file directly in eclipse.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.