mybatis Parameter index out of range (1 > number of parameters, which is 0)
今天遇到了一個有意思的問題,看錯誤資訊提示,好像是有個引數沒有匹配上,具體錯誤資訊如下:
### SQL: SELECT count(*) FROM (SELECT * FROM testTable) table_count
; SQL []; Parameter index out of range (1 > number of parameters, which is 0).; nested exception is java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
### Cause: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:108)
; SQL []; Parameter index out of range (1 > number of parameters, which is 0).; nested exception is java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:74)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:399)
at com.sun.proxy.$Proxy24.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:205)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:119)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
at com.sun.proxy.$Proxy66.gettestList(Unknown Source)
at org.jiankunking.test.database.service.Impl.EctestServiceImpl.gettestList(EctestServiceImpl.java:44)
at org.jiankunking.test.database.service.Impl.EctestServiceImpl$$FastClassBySpringCGLIB$$53317614.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:649)
at org.jiankunking.test.database.service.Impl.EctestServiceImpl$$EnhancerBySpringCGLIB$$575d6ee1.gettestList(<generated>)
at org.jiankunking.test.product.controller.EctestController.gettestList(EctestController.java:54)
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.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.workholic.framework.common.ligeruiUtils.ServerPageFilter.doFilter(ServerPageFilter.java:44)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
at org.workholic.framework.web.security.shirofilterfactory.ShiroFilterFactoryx$SpringShiroFilterx.doFilterInternal(ShiroFilterFactoryx.java:103)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:937)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:872)
at com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3399)
at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3384)
at com.mysql.jdbc.PreparedStatement.setString(PreparedStatement.java:4110)
at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_setString(FilterChainImpl.java:2823)
at com.alibaba.druid.filter.FilterAdapter.preparedStatement_setString(FilterAdapter.java:1340)
at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_setString(FilterChainImpl.java:2820)
at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.setString(PreparedStatementProxyImpl.java:560)
at com.alibaba.druid.pool.DruidPooledPreparedStatement.setString(DruidPooledPreparedStatement.java:365)
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.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:70)
at com.sun.proxy.$Proxy140.setString(Unknown Source)
at org.apache.ibatis.type.StringTypeHandler.setNonNullParameter(StringTypeHandler.java:31)
at org.apache.ibatis.type.StringTypeHandler.setNonNullParameter(StringTypeHandler.java:26)
at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:50)
at org.apache.ibatis.type.UnknownTypeHandler.setNonNullParameter(UnknownTypeHandler.java:45)
at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:50)
at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:81)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:80)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:61)
at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:74)
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:59)
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77)
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.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49)
at com.github.pagehelper.SqlUtil._processPage(SqlUtil.java:386)
at com.github.pagehelper.SqlUtil.processPage(SqlUtil.java:329)
at com.github.pagehelper.PageHelper.intercept(PageHelper.java:150)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:60)
at com.sun.proxy.$Proxy138.query(Unknown Source)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)
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.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:386)
... 69 more
小注:
SELECT count() FROM (SELECT FROM testTable) table_count
FORM裡面的sql進行了簡化。
問題分析:
1、通過輸出出來的sql,到資料庫中執行是沒有問題,即:SELECT count(*) FROM (複雜sql) table_count執行沒有問題,相應的變數也已經替換成功
2、在出現這個錯誤之前,我只進行了一個操作,那就是在mybatis的xml檔案中註釋了兩行sql,如下圖:
解決:
去掉註釋或者直接刪除這兩行程式碼,問題消失。
說明mybatis在處理xml中這種註釋的時候存在一定的問題。
小注:
我註釋程式碼的操作是在idea中通過ctrl+/來操作的
作者:jiankunking 出處:http://blog.csdn.net/jiankunking
相關文章
- java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2)的解決方法JavaSQLExceptionIndex
- python爬蟲 -IndexError: list index out of range報錯Python爬蟲IndexError
- 解決Parameter '__frch_item_0' not found. Available parameters 問題AI
- Caused by: java.lang.IllegalArgumentException: port out of range:-1JavaException
- 關於Pyinstaller在打包Streamlit程式時遇到的IndexError:tuple index out of rangeIndexError
- height_scale = scales[2] IndexError: index 2 is out of bounds for axis 0 with size 0IndexError
- Android Audio HAL 介面介紹之 adev_set_parameters()和out_set_parameters()Androiddev
- CSS :out-of-range 選擇器CSS
- Spring Initializr - LSP - Failed to fetch Generation from Spring IO: port out of range: -1SpringAI
- 說說C# 8.0 新增功能Index和Range的^0是什麼?C#Index
- [LeetCode] 1953. Maximum Number of Weeks for Which You Can WorkLeetCode
- [20230908]Oracle Index Range Scan with LIKE Condition on Wildcard '_'.txtOracleIndex
- java.sql.BatchUpdateException: Date truncation: Out of range value for column xxxxxJavaSQLBATException
- tensorflow訓練時警告:BaseCollectiveExecutor::StartAbort Out of range: End of sequence
- C# 使用 Index 和 Range 簡化集合操作C#Index
- java.lang.IndexOutOfBoundsException: Index: 0, Size: 0JavaIndexException
- PostgreSQL/LightDB- Tried to send an out-of-range integer as a 2-byte valueSQL
- 隨筆:MySQL:eq_range_index_dive_limit 索引下探介面MySqlIndexMIT索引
- 使用mybatis報錯:Error setting non null for parameter #4 with JdbcType TIMESTAMPMyBatisErrorNullJDBC
- Python錯題本(1)range()Python
- sky-take-out chapter 1APT
- [LeetCode] 191. Number of 1 BitsLeetCode
- Required parameter $xxx follows optional parameter $yyyUI
- 023 Given an integer n. get the number of 0, 2, 4 from all the values from [0, n]
- skipped: maximum number of running instances reached (1)
- Number 1 — 程式設計入門程式設計
- laravel-admin用dingo/api報sha1() expects parameter 1 to be strLaravelGoAPI
- TypeError: object() takes no parametersErrorObject
- java.sql.SQLException: No value specified for parameter 1 異常分析JavaSQLException
- ORA-16024: parameter LOG_ARCHIVE_DEST_1 cannot be parsedHive
- 13.MyBatis報錯:Error querying database. Cause: org.apache.ibatis.binding.BindingException: ParameterMyBatisErrorDatabaseApacheException
- UNREFERENCED_PARAMETER
- Solaris awk: syntax error near line 1 awk: bailing out near line 1ErrorAI
- v$parameter gv$parameter 檢視 DDL 與隱含引數
- SlZORk9SMkRMSVpUR1VDQ0tWTUZDTVNNSkZHVU1WS0hJTk5GSVRLTklaS0ZRTVI1SFU2UQ==VR
- Mybatis技術內幕(1):Mybatis簡介MyBatis
- 【OCP最新題庫解析(052)--題1】Which is true about the SYSTEM and SYSAUX...UX
- python parameter引數Python
- LTSPICE parameter設定