Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException:

最近在该SSM项目遇到BadSqlGrammarException,即低级语法错误。截图如下:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: 
### Error querying database.  Cause: 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 'schedule
        where movie_id= 8' at line 1
### The error may exist in com/shixun/mapper/ScheduleMapper.xml
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select count(*) form schedule         where movie_id= 8
### Cause: 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 'schedule
        where movie_id= 8' at line 1
; bad SQL grammar []; nested exception is 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 'schedule
        where movie_id= 8' at line 1
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1013)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:897)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:655)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:118)

遇到这种情况,可以采取以下思路排错:
1.检查SQL语句是否有拼写错误,比如(from,select等关键字);
2.检查是否有数据库表字段名冲突;
3.是否符合SQL基于CRUD的基本语法;

经过排查,我遇到的问题就是mybatis里面的SQL语句的from拼写错误,请各位读者引以为鉴。


版权声明:本文为qq_51447436原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。