在Spring Boot应用程序中获取MySQL语法错误

问题描述 投票:0回答:2

我正在通过将Spring Boot与Gradle结合使用并尝试将其连接到计算机上的MySQL来制作一个简单的应用程序。当我运行该应用程序时,出现以下错误:

java.sql.SQLSyntaxErrorException:您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以在'load(id integer not null,customer varchar(255),date datetime not null,destin')第1行附近使用正确的语法

现在我只有一个类,Load,这是它的样子:

@Entity
public class Load {
    public Load(){}
    @Id
    @GeneratedValue
    private int id;

    @NotBlank(message = "Customer field must not be blank")
    @NotNull
    @Size(max = 100, message = "Customer name too long!")
    private String customer;

    @NotBlank(message = "Destination field must not be blank")
    @NotNull
    @Size(max = 100, message = "Destination name too long!")
    private String destination;

    @NotBlank(message = "Driver field must not be blank")
    @NotNull
    @Size(max = 50, message = "Driver name too long!")
    private String driver;


    @NotNull
    private Date date;

    public Load(String customer, String destination, String driver, Date date) {
        this.customer = customer;
        this.destination = destination;
        this.driver = driver;
        this.date = date;
    }

我不太确定我在本课程中创建的内容在哪里

java mysql spring-boot gradle persistence
2个回答
0
投票

[LOAD是MySQL中的reserved keyword,这就是为什么错误消息指向SQL语句中的名称load(“ near'load”)附近的原因。

[例如,通过使用name批注的@Entity属性指定值名称来重命名表

@Entity(name = "customer_load")
public class Load {

0
投票

您正在尝试使用MySQL保留关键字Load作为问题的表名。

但是您也可以在使用反引号字符时使用保留关键字。

@Entity
@javax.persistence.Table(name = "`load`")
public class Load{
   ...
}
© www.soinside.com 2019 - 2024. All rights reserved.