无法执行语句; SQL [n / a];嵌套的异常是org.hibernate.exception.SQLGrammarException:无法执行语句

时间:2018-08-16 06:08:03

标签: java spring-boot

我对开发非常陌生。我正在使用Spring Boot在Java中执行库管理应用程序。向新用户注册时出现上述错误。

我的应用程序正在运行,但是在进行注册之类的操作时出现上述错误,但是在单击“注册”按钮后出现了以上错误。

这是我的代码

我的实体类:

@Entity
@Table(name="mytable")
public class User {

    @Id
    private int id;
    private String username;
    private String firstname;
    private String lastname;
    private int age;
    private String password;

    public User() {

    }


    public User(String username, String firstname, String lastname, int age, String password) {
        super();
        this.username = username;
        this.firstname = firstname;
        this.lastname = lastname;
        this.age = age;
        this.password = password;
    }
 omit getters and setters

这是我的控制人:

@Controller
public class ApplicationController {

    @Autowired
    UserService userService;

    @RequestMapping("/welcome")
    public String Welcome(HttpServletRequest request) {
        request.setAttribute("mode", "MODE_HOME");
        return "welcomepage";
    }

    @GetMapping("/register")
    public String registration(HttpServletRequest request) {
        request.setAttribute("mode", "MODE_REGISTER");
        return "welcomepage";
    }

    @PostMapping("/save-user")
    public String registerUser(@ModelAttribute User user, BindingResult bindingResult, HttpServletRequest request) {
        userService.saveMyUser(user);
        request.setAttribute("mode", "MODE_HOME");
        return "welcomepage";
    }

    @GetMapping("/show-users")
    public String showAllUsers(HttpServletRequest request) {
        request.setAttribute("users", userService.showAllUsers());
        request.setAttribute("mode", "ALL_USERS");
        return "welcomepage";
    }

    @RequestMapping("/delete-user")
    public String deleteUser(@RequestParam int id, HttpServletRequest request) {
        userService.deleteMyUser(id);
        request.setAttribute("users", userService.showAllUsers());
        request.setAttribute("mode", "ALL_USERS");
        return "welcomepage";
    }

    @RequestMapping("/edit-user")
    public String editUser(@RequestParam int id,HttpServletRequest request) {
        request.setAttribute("user", userService.editUser(id));
        request.setAttribute("mode", "MODE_UPDATE");
        return "welcomepage";
    }

    @RequestMapping("/login")
    public String login(HttpServletRequest request) {
        request.setAttribute("mode", "MODE_LOGIN");
        return "welcomepage";
    }

    @RequestMapping ("/login-user")
    public String loginUser(@ModelAttribute User user, HttpServletRequest request) {
        if(userService.findByUsernameAndPassword(user.getUsername(), user.getPassword())!=null) {
            return "homepage";
        }
        else {
            request.setAttribute("error", "Invalid Username or Password");
            request.setAttribute("mode", "MODE_LOGIN");
            return "welcomepage";

        }
    }

}

[运行应用程序时,这是我的注册表格] [1]

  [1]: https://i.stack.imgur.com/33QvJ.png

这是我的application.properties

spring.mvc.view.prefix=/WEB-INF/view/
spring.mvc.view.suffix=.jsp

#Persistence Related Code
spring.datasource.url=jdbc:mysql://localhost/db_example?useSSL=false
spring.datasource.username=springuser
spring.datasource.password=ThePassword

spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
logging.level.org.hibernate.SQL=debug

但是,单击注册按钮后,出现上述错误。有人可以帮我吗?

0 个答案:

没有答案