org.springframework.web.util.NestedServletException: Request processing failed; nested exception is
重要的话说在前面!!!
Leave是MySQL的关键字!
Leave是MySQL的关键字!
Leave是MySQL的关键字!
今天发生了一件很诡异的Exception,具体如下:
Type 异常报告
消息 Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException:
描述 服务器遇到一个意外的情况,阻止它完成请求。
Exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'leave WHERE studentId = 1' at line 1 ### The error may exist in com/kwxy/hyt/mapper/LeaveMapper.xml ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: SELECT count(0) FROM leave WHERE studentId = 1 ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'leave WHERE studentId = 1' at line 1 ; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'leave WHERE studentId = 1' at line 1 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857) javax.servlet.http.HttpServlet.service(HttpServlet.java:634) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) com.kwxy.hyt.filter.SystemContextFilter.doFilter(SystemContextFilter.java:38) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
Root Cause
org.springframework.jdbc.BadSqlGrammarException: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'leave WHERE studentId = 1' at line 1 ### The error may exist in com/kwxy/hyt/mapper/LeaveMapper.xml ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: SELECT count(0) FROM leave WHERE studentId = 1 ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'leave WHERE studentId = 1' at line 1 ; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'leave WHERE studentId = 1' at line 1 org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:231) org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73) org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371) com.sun.proxy.$Proxy16.selectList(Unknown Source) org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:198) org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:119) org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63) org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52) com.sun.proxy.$Proxy21.findBySqlRerturnEntity(Unknown Source) com.kwxy.hyt.base.BaseServiceImpl.findBySqlRerturnEntity(BaseServiceImpl.java:280) com.kwxy.hyt.controller.LeaveController.myleave(LeaveController.java:177) java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.base/java.lang.reflect.Method.invoke(Method.java:567) org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706) org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857) javax.servlet.http.HttpServlet.service(HttpServlet.java:634) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) com.kwxy.hyt.filter.SystemContextFilter.doFilter(SystemContextFilter.java:38) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
可以看到异常很明确地告诉我是SQL语句异常,可是我当时还不知道具体是哪里出了问题,我就把这句SQL一遍又一遍地在Navicat上面执行,发现完全没有问题啊!
然后我以为是mybatis地xml没配置好,随即有用原先的方式演示了一遍,也完全没有问题啊!!!
但是,但是!一旦换成英文版的请假“leave”就必定出错!
然后我就这样陷入了蜜汁自信(我写的SQL一定没有错!)疯狂的找是不是因为反射或者代理出问题了导致SQL语句解析有问题...就这样我耗了七个多小时,,忽然灵机一动,,,是不是‘leave'是MySQL的关键字啊?然后搜了一下...我TM心态崩了啊!学了三四年、用了三四年SQL从来都不知道’leave'是关键字...我这辈子都不会忘记了,都不好意思说我学过数据库语言!