数据库不接受西里尔字母

时间:2018-08-24 17:17:18

标签: java mysql spring encoding

我在数据库中的西里尔字母字符有问题,并在Java spring中使用它。

从Chrome浏览器图像中: enter image description here

我通过以下方式创建数据库:

create database dbname
character set utf8
collate utf8_general_ci;

示例数据库表: (自动创建):

@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;
    }
   }

保存实体方式:

@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

但是,结果是,当我保存数据库西里尔字母字符时,所有字符都显示为'?'。

要解决此问题,我还必须做什么?

1 个答案:

答案 0 :(得分:0)

从字符串中删除 amp;

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

在application.properties文件中。