【问题标题】:Spring: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use nearSpring:您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,以了解在附近使用的正确语法
【发布时间】:2018-06-08 03:13:14
【问题描述】:

首先我很抱歉,因为我的英语不好。 我正在研究 Spring Framework,并且正在使用 Spring Boot、Spring Data、Spring MVC 制作一个简单的应用程序。

现在我有一个错误,但我不知道为什么。

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 你的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,以在第 1 行的 'describe='Education', name_room='Boston', id_status='2' where id_room='1'' 附近使用正确的语法

这是我的代码:

Room Model

    @Entity
    @Table(name ="room")
     public class Room implements Serializable {
     private static final long serialVersionUID = 1L;
     @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(name = "ID_room", nullable = false)
        private String id;


        @Column(name = "name_room", nullable = false)
        private String name;


        @Column(name = "Describe")
        private String describe;

        @Column(name = "ID_status")
        private String status;

        public Room() {
            super();
        }

        public Room(String id, String name, String describe, String status) {
            super();
            this.id = id;
            this.name = name;
            this.describe = describe;
            this.status = status;

        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getDescribe() {
            return describe;
        }

        public void setDescribe(String describe) {
            this.describe = describe;
        }

        public String getStatus() {
            return status;
        }

        public void setStatus(String status) {
            this.status = status;
        }


}

RoomController

    @GetMapping("/manager/{id}/edit")
    public String edit(@PathVariable String id, Model model) {
        model.addAttribute("room", romService.findOne(id));
        return "roomForm";
    }

    @PostMapping("/manager/save")
    public String save(@Valid Room room, BindingResult result, RedirectAttributes redirect) {
        if (result.hasErrors()) {
            return "roomform";
        }
        romService.save(room);
        redirect.addFlashAttribute("success", "Saved user successfully!");
        return "redirect:/manager";
    }

代码正在运行,但我有一个 SQL 错误。我不知道为什么。请帮助我

Hibernate: update room set describe=?, name_room=?, id_status=? where id_room=?
2018-06-08 09:41:12.881  WARN 9308 --- [io-8080-exec-10] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 1064, SQLState: 42000
2018-06-08 09:41:12.882 ERROR 9308 --- [io-8080-exec-10] o.h.engine.jdbc.spi.SqlExceptionHelper   : You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'describe='Education', name_room='Boston', id_status='2' where id_room='1'' at line 1

【问题讨论】:

    标签: spring spring-mvc spring-data-jpa


    【解决方案1】:

    这是因为'describe'是Mysql中的关键字,不应该使用。为该字段指定一个不同的名称。

    或者如果你想使用关键字作为字段名,那么只描述然后这样放。在 `describe` 之间(反引号字符)

    【讨论】:

    • 关键字“用法”也发生在我身上。你的回答有帮助。 ty
    • 很高兴它帮助了你...:)
    猜你喜欢
    • 1970-01-01
    • 2017-02-14
    • 2015-03-30
    • 1970-01-01
    • 1970-01-01
    • 2018-04-08
    • 2018-07-13
    • 2019-05-31
    • 1970-01-01
    相关资源
    最近更新 更多