findByCache总是报500错误:java.sql.SQLExceptio

报错:

2020-12-17 10:18:10

[ERROR]-[Thread: XNIO-17 task-1]-[com.jfinal.core.ActionHandler.handle()]: test.TimeTest.getAll3() : /time/getAll3

com.jfinal.plugin.activerecord.ActiveRecordException: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).

at com.jfinal.plugin.activerecord.Model.find(Model.java:702)

at com.jfinal.plugin.activerecord.Model.findByCache(Model.java:958)

at dao.impl.TimeImpl.getAll3(TimeImpl.java:51)

at dao.impl.TimeImpl$$EnhancerByCGLIB$$3c227a5d.CGLIB$getAll3$8(<generated>)

at dao.impl.TimeImpl$$EnhancerByCGLIB$$3c227a5d$$FastClassByCGLIB$$470e3d30.invoke(<generated>)

at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)

at com.jfinal.ext.proxy.CglibCallback.lambda$intercept$0(CglibCallback.java:58)

at com.jfinal.aop.Invocation.invoke(Invocation.java:101)

at com.jfinal.ext.proxy.CglibCallback.intercept(CglibCallback.java:63)

at dao.impl.TimeImpl$$EnhancerByCGLIB$$3c227a5d.getAll3(<generated>)

at test.TimeTest.getAll3(TimeTest.java:38)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.base/java.lang.reflect.Method.invoke(Method.java:567)

at com.jfinal.aop.Invocation.invoke(Invocation.java:97)

at com.jfinal.plugin.activerecord.tx.TxByMethods.intercept(TxByMethods.java:57)

at com.jfinal.aop.Invocation.invoke(Invocation.java:91)

at com.jfinal.ext.interceptor.SessionInViewInterceptor.intercept(SessionInViewInterceptor.java:44)

at com.jfinal.aop.Invocation.invoke(Invocation.java:91)

at com.jfinal.core.ActionHandler.handle(ActionHandler.java:88)

at handler.XssHandler.handle(XssHandler.java:14)

at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:90)

at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)

at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)

at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)

at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)

at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)

at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)

at io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68)

at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132)

at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)

at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)

at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)

at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)

at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)

at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)

at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

at io.undertow.servlet.handlers.SessionRestoringHandler.handleRequest(SessionRestoringHandler.java:119)

at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:269)

at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:78)

at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:133)

at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:130)

at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)

at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)

at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:249)

at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:78)

at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:99)

at io.undertow.server.Connectors.executeRootHandler(Connectors.java:376)

at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)

at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)

at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)

at java.base/java.lang.Thread.run(Thread.java:830)

Caused by: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)

at com.mysql.cj.jdbc.ClientPreparedStatement.checkBounds(ClientPreparedStatement.java:1365)

at com.mysql.cj.jdbc.ClientPreparedStatement.getCoreParameterIndex(ClientPreparedStatement.java:1378)

at com.mysql.cj.jdbc.ClientPreparedStatement.setObject(ClientPreparedStatement.java:1662)

at com.alibaba.druid.pool.DruidPooledPreparedStatement.setObject(DruidPooledPreparedStatement.java:476)

at com.jfinal.plugin.activerecord.dialect.Dialect.fillStatement(Dialect.java:230)

at com.jfinal.plugin.activerecord.Model.find(Model.java:688)

at com.jfinal.plugin.activerecord.Model.find(Model.java:700)

... 54 more


出错接口代码:


  //可以获取返回值

@Override

public Page<Time> getAll(String userId,int pageIndex, int pageSize) {

return dao.paginateByCache(Util1.Time_getAll, Util1.Time_getAll+pageIndex,pageIndex,pageSize, "select * ","from d_time where userid=?",userId);

    }

       //可以获取返回值

@Override

public List<Time> getAll2(String userId) {

return dao.findAll();

    }

  //一直报500错误,sql错误,百思不得其解,大佬知道是怎么回事吗

@Override

public List<Time> getAll3(String userId) {

return dao.findByCache(Util1.Time_getAll, Util1.Time_getAll+"1", "select * ","from d_time where userid=?",userId);

    }


评论区

JFinal

2020-12-17 12:04

报错的那个调错了方法,注意看你调用的是:findByCache

yuwen01

2020-12-17 14:35

@JFinal大佬 findByCache不是查询后结果保存到对应缓存里面吗?我的想法就是查询后保存到缓存里面,没有调错方法呀!

杜福忠

2020-12-17 14:42

@yuwen01 findByCache(String cacheName, Object key, String sql, Object... paras)
看看参数列表是什么,你的"select * ","from ,SQL是整条的不能分开写,不是分页那个函数

yuwen01

2020-12-17 15:02

@杜福忠 可以了,非常感谢大佬!

yuwen01

2020-12-17 15:03

@JFinal 感谢社区的你每天及时回复和处理!

热门反馈

扫码入社