我正在通过将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;
}
我不太确定我在本课程中创建的内容在哪里
[LOAD
是MySQL中的reserved keyword,这就是为什么错误消息指向SQL语句中的名称load
(“ near'load”)附近的原因。
[例如,通过使用name
批注的@Entity
属性指定值名称来重命名表
@Entity(name = "customer_load")
public class Load {
您正在尝试使用MySQL保留关键字Load
作为问题的表名。
但是您也可以在使用反引号字符时使用保留关键字。
@Entity
@javax.persistence.Table(name = "`load`")
public class Load{
...
}