sql執行拋異常:Caused by: net.sf.jsqlparser.parser.ParseException
阿新 • • 發佈:2019-02-08
Caused by: net.sf.jsqlparser.parser.ParseException: Encountered " "(" "( "" at line 3, column 11.
Was expecting one of:<EOF>
"AS" ...
"DO" ...
"INTO" ...
"FROM" ...
...
1.java程式碼:
確定是由於【PageHelper.orderBy(params.get("orderBy").toString());】這段程式碼引起的
@Override public List<Clerk> findClerkList(Map<String, Object> params) { PageHelper.startPage(((Integer) params.get("pageNum")), ((Integer) params.get("pageSize"))); if (params.containsKey("orderBy")) { if (!StringUtil.empty(params.get("orderBy").toString())) { PageHelper.orderBy(params.get("orderBy").toString()); } } List<Clerk> clerkList = clerkMapper.findClerkList(params); for (Clerk c : clerkList){ String sellerStartLevel = StartLevelEnum.getEnumValueByKey(c.getSellerStartLevel()); c.setSellerStartLevel(sellerStartLevel); } return clerkList; }
完整異常如下:
由【net.sf.jsqlparser.JSQLParserException】可看出是因為組裝的sql語句解析過程中丟擲"非RuntimeException異常",異常被程式捕抓處理且未出現新異常,異常後的程式碼繼續執行,所以不影響一個完整Retrieve操作。而一些"RuntimeException異常",例如:空指標(NullPointerException)、陣列越界(IndexOutOfBoundsException)、型別轉換(ClassCastException)等會被JVM自動處理,會在console控制檯捕抓並列印異常日誌。
==> Parameters: net.sf.jsqlparser.JSQLParserException at net.sf.jsqlparser.parser.CCJSqlParserUtil.parse(CCJSqlParserUtil.java:51) at com.github.orderbyhelper.OrderByParser.converToOrderBySql(OrderByParser.java:27) at com.github.orderbyhelper.sqlsource.OrderByStaticSqlSource.getBoundSql(OrderByStaticSqlSource.java:39) at com.github.pagehelper.sqlsource.PageDynamicSqlSource.getDefaultBoundSql(PageDynamicSqlSource.java:69) at com.github.pagehelper.sqlsource.PageSqlSource.getBoundSql(PageSqlSource.java:58) at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:265) at com.github.pagehelper.SqlUtil.doProcessPage(SqlUtil.java:571) at com.github.pagehelper.SqlUtil._processPage(SqlUtil.java:410) at com.github.pagehelper.SqlUtil.processPage(SqlUtil.java:377) at com.github.pagehelper.PageHelper.intercept(PageHelper.java:227) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:57) at com.sun.proxy.$Proxy45.query(Unknown Source) at sun.reflect.GeneratedMethodAccessor52.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:46) at com.xfj.base.common.service.myBatisInterceptor.intercept(myBatisInterceptor.java:49) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:57) at com.sun.proxy.$Proxy45.query(Unknown Source) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:98) at sun.reflect.GeneratedMethodAccessor66.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:355) at com.sun.proxy.$Proxy36.selectList(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:195) at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:114) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:58) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:43) at com.sun.proxy.$Proxy233.findClerkList(Unknown Source) at com.xfj.base.secretary.service.serviceimpl.ClerkServiceImpl.findClerkList(ClerkServiceImpl.java:36) at com.xfj.base.secretary.controller.ClerkController.initClerkTable(ClerkController.java:81) at com.xfj.base.secretary.controller.ClerkController$$FastClassByCGLIB$$1d26f873.invoke(<generated>) at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:688) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:50) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621) at com.xfj.base.secretary.controller.ClerkController$$EnhancerByCGLIB$$a921c7f2.initClerkTable(<generated>) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:368) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380) at com.xfj.base.security.common.MySecurityFilter.invoke(MySecurityFilter.java:79) at com.xfj.base.security.common.MySecurityFilter.doFilter(MySecurityFilter.java:63) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380) at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380) at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380) at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380) at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:119) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380) at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380) at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380) at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:177) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380) at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380) at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380) at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380) at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380) at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:169) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418) at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230) at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.Server.handle(Server.java:326) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:943) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410) at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582) Caused by: net.sf.jsqlparser.parser.ParseException: Encountered " "(" "( "" at line 3, column 11. Was expecting one of: <EOF> "AS" ... "DO" ... "INTO" ... "FROM" ... "WHERE" ... "XML" ... "GROUP" ... "VALUE" ... "HAVING" ... "REPLACE" ... "TRUNCATE" ... "CAST" ... "PARTITION" ... "EXTRACT" ... "MATERIALIZED" ... "START" ... "CONNECT" ... "SIBLINGS" ... "COLUMN" ... "NULLS" ... "FIRST" ... "LAST" ... "ROWS" ... "RANGE" ... "FOLLOWING" ...
2. 從後臺控制檯列印的日誌中抓取執行的sql語句:
SELECT 1 AS all_apply_customer, count(if(xataa.accept_status = 1, TRUE, NULL)) AS accept_apply_customer, count(if(xataa.accept_status = 0, TRUE, NULL)) AS reject_apply_customer, count(if(xataa.accept_status = 2, TRUE, NULL)) AS invalid_apply_customer FROM xft_apply_task_assign_agent xataa ORDER BY all_apply_customer DESC
3.從PageHelper官網看到其是引用了sql解析工具jsqlparser.jar,是工具包丟擲的異常
雖然後臺丟擲JSQLparseException,但是不影響sql查詢結果。
原因是count函式中嵌套了if函式導致拋異常,不使用“count(if(exprt))”巢狀函式就不會出現異常;
看到有博主留言說將sql寫成檢視就不會出現這個異常,親測後,仍然會拋異常;
升級pagehelper的版本為v4.1.6仍舊會拋異常;