java - 在 Spring Boot 应用程序中获取 MySQL 语法错误
问题描述
我正在制作一个简单的应用程序,将 Spring Boot 与 Gradle 一起使用,并尝试将其连接到我计算机上的 MySQL。当我运行应用程序时,我收到以下错误:
java.sql.SQLSyntaxErrorException:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 'load (id integer not null, customer varchar(255), date datetime not null,destin' 附近使用正确的语法
现在我只有一个类,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;
}
我不太确定我在这堂课中创建的问题出在哪里
解决方案
您正在尝试使用 MySQL 保留关键字Load
作为表名,这就是问题所在。
但是您也可以在使用反引号字符时使用保留关键字。
@Entity
@javax.persistence.Table(name = "`load`")
public class Load{
...
}
推荐阅读
- python - 查找最大值子数组的索引并将其应用于该子数组
- java - 将 dat 转换为链表
- java - 多次运行测试方法而不使用循环
- r - 如何找到在 R 中产生最大 colMeans 的集群?
- amazon-s3 - 从 spring-cloud-streams 推送到 aws-kinesis 时导致额外标头的原因是什么?
- python - 如何让speedrun计时器保持在最前面
- java - 使用 for 循环保存多个 .txt 文件
- python-3.x - 如何通过延迟加载硒网页抓取
- python - 如何有效限制 Python 中 SimPy 生成的进程?
- python - Method Not Allowed 请求的 URL 不允许使用该方法。(烧瓶)