分页order by报错

求教波总!!!

jfinal 3.2 分页时使用中文字段排序报错

期望的sql:select *  FROM team  ORDER BY convert(hotel_name USING gbk)

控制台报错如下:

Sql: select count(*)  FROM team  USING gbk)
八月 21, 2017 11:17:59 下午 com.jfinal.core.ActionHandler error
严重: /pc/team
com.jfinal.plugin.activerecord.ActiveRecordException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'USING gbk)' at line 1
 at com.jfinal.plugin.activerecord.Model.doPaginate(Model.java:337)
 at com.jfinal.plugin.activerecord.Model.paginate(Model.java:313)
 at com.as.service.TeamService.pagenate(TeamService.java:46)
 at com.as.controller.sys.TeamController.index(TeamController.java:33)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at com.jfinal.aop.Invocation.invoke(Invocation.java:73)
 at com.as.config.interceptors.AuthInterceptor.intercept(AuthInterceptor.java:32)
 at com.jfinal.aop.Invocation.invoke(Invocation.java:67)
 at com.jfinal.core.ActionHandler.handle(ActionHandler.java:74)
 at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:73)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
 at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
 at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
 at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670)
 at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
 at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
 at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
 at java.lang.Thread.run(Thread.java:745)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'USING gbk)' at line 1
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
 at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
 at com.mysql.jdbc.Util.getInstance(Util.java:386)
 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
 at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
 at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
 at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2683)
 at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2144)
 at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2310)
 at com.alibaba.druid.pool.DruidPooledPreparedStatement.executeQuery(DruidPooledPreparedStatement.java:227)
 at com.jfinal.plugin.activerecord.DbPro.query(DbPro.java:80)
 at com.jfinal.plugin.activerecord.Db.query(Db.java:70)
 at com.jfinal.plugin.activerecord.Model.doPaginateByFullSql(Model.java:351)
 at com.jfinal.plugin.activerecord.Model.doPaginate(Model.java:335)
 ... 30 more

评论区

JFinal

2017-08-21 23:32

order by 语句无法被 MySqlDialect 移除,用一下 paginateByFullSql 就好,看一下手册中有关这个方法的使用

大部分情况用 paginate 就可以

zxiandjfinal

2017-08-22 21:40

@JFinal 搞定 谢波总

热门反馈

扫码入社