0

I have issue with Cyrillic character in database, and usage it java spring.

From chrome-browser image: enter image description here

I create my database in next way:

create database dbname
character set utf8
collate utf8_general_ci;

Example database table: (created automatically):

@Entity(name = "words")
public class Words {

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    @Column(name = "word")
    private String word;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getWord() {
        return word;
    }

    public void setWord(String word) {
        this.word = word;
    }
   }

Save entity way:

@Repository
public interface WordRepository extends JpaRepository<Word, Long> {
}

+

@Service 
public class WordService{

    @Autovired
    private WordRepository wordRepository;

    public saveAll(List<Word> wordList){
        wordRepository.saveAll(wordList);
    }
}

application.properties :

#Database settings
spring.datasource.url=jdbc:mysql://localhost:3306/dbname?useUnicode=yes&amp;characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update

spring.datasource.tomcat.connection-properties=useUnicode=true;characterEncoding=utf-8;
spring.datasource.sql-script-encoding=UTF-8

But, in result, when I save in database Cyrillic characters, all shows as '?'.

What else I must to do for resolve this?

Valentyn Hruzytskyi
  • 1,772
  • 5
  • 27
  • 59

1 Answers1

1

Remove amp; from string

spring.datasource.url=jdbc:mysql://localhost:3306/dbname?useUnicode=yes&amp;characterEncoding=utf-8

in application.properties file.

Mark
  • 88
  • 7