【发布时间】:2017-11-19 03:51:28
【问题描述】:
我的application.properties 设置如下:
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
在我的pom.xml我有这样的属性设置:
<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>
我的实体: @实体 公共类 DailyRashifalEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String date;
private int rollno;
private String name;
//Constructors and getters/setters
}
问题 1: 如果我使用上述设置,则会出现异常
java.sql.SQLException: Incorrect string value: '\xE0\xA4\xA7\xE0\xA4\xBE...
问题2:如果我将数据源网址更改为:
spring.datasource.url = jdbc:mysql://localhost:3306/dbname
我的数据库中的 unicode 是这样保存的
29 | 2074-03-04 | 3 | ?????????????? ?????,?????? ??????, ??????????? ????? ? ???? ???? ???? ??????
如何我可以在 Mysql 中保存它们,就像它们在 unicode 而不是获取所有 unicode 数据已转换为????????。
【问题讨论】:
-
删除数据库并重试。你可以设置
spring.jpa.hibernate.ddl-auto = create进行测试。 -
您是否也尝试过在连接上设置字符集?
-
@premkumar 不走运..
-
@FMashiro 最近几天我开始春天了,我不太确定你说的是什么感觉。你能解释一下吗?
-
为
show create database dbname粘贴输出
标签: mysql spring spring-boot unicode spring-jdbc