java - Spring Boot 应用程序中出现 MySQL 语法错误

标签 java mysql spring-boot gradle persistence

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

java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'load (id integer not null, customer varchar(255), date datetime not null, destin' at line 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;
    }

我不太确定我在此类中创建的内容问题出在哪里

最佳答案

LOADreserved keyword在 MySQL 中,这就是为什么错误消息指向 SQL 语句中的名称 load(“near 'load”)。

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

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

关于java - Spring Boot 应用程序中出现 MySQL 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61313890/

相关文章:

Java 游戏 - 潜艇 killer - 只要按下向下键就发射炸弹

java - 如何在 Android Studio 上从抽屉导航的 fragment 移动到 Activity?

php - 如何将域名页面重定向到另一台主机?

java - 使用 Spring Boot : Could not resolve placeholder 进行 Maven 资源过滤

spring-boot - 如何使用 Spring Security 在 Spring Boot 中设置上下文路径

java - 同步对象: Locking Code vs Locking Object

java - 静态内部类中的静态 block

mysql - SQL,如何从不同表中选择属性?

mysql - 使用 "OR"语句时Mysql索引出现问题

在 IntelliJ Idea 中未为 Kotlin @ConfigurationProperties 类生成 spring-configuration-metadata.json 文件