sql运行抛异常:Caused by: net.sf.jsqlparser.parser.ParseException

Caused by: net.sf.jsqlparser.parser.ParseException: Encountered " "(" "( "" at line 3, column 11.

Was expecting one of:
     
    "AS" ...
    "DO" ...
    "INTO" ...

    "FROM" ...

    ...

  1.java代码:

    确定是由于【PageHelper.orderBy(params.get("orderBy").toString());】这段代码引起的

    @Override
    public List findClerkList(Map 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 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()
	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()
	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:
     
    "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,是工具包抛出的异常

sql运行抛异常:Caused by: net.sf.jsqlparser.parser.ParseException_第1张图片

虽然后台抛出JSQLparseException,但是不影响sql查询结果。


原因是count函数中嵌套了if函数导致抛异常,不使用“count(if(exprt))”嵌套函数就不会出现异常;

看到有博主留言说将sql写成视图就不会出现这个异常,亲测后,仍然会抛异常;

升级pagehelper的版本为v4.1.6仍旧会抛异常;

你可能感兴趣的:(数据库,mysql)