在做SSM整合时,关于抛出 java.sql.SQLException: Parameter index out of range (3 > number of parameter 的问题

第一次写博客,写的不好望谅解!!!!!!!!!!!!!!!!!

最近在做毕业设计,用SSM框架编写一个Web项目,在做到根据名称模糊分页查询时,抛出了java.sql.SQLException: Parameter index out of range (3 > number of parameter异常,各种尝试    这个异常依然没有解决

 

java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2).
	com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1084)
	com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
	com.mysql.jdbc.SQLError.createSQLException(SQLError.java:973)
	com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
	com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3688)
	com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3670)
	com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3715)
	com.mysql.jdbc.PreparedStatement.setInt(PreparedStatement.java:3659)
	org.apache.commons.dbcp.DelegatingPreparedStatement.setInt(DelegatingPreparedStatement.java:117)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	java.lang.reflect.Method.invoke(Unknown Source)
	org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:67)
	com.sun.proxy.$Proxy28.setInt(Unknown Source)
	org.apache.ibatis.type.IntegerTypeHandler.setNonNullParameter(IntegerTypeHandler.java:31)
	org.apache.ibatis.type.IntegerTypeHandler.setNonNullParameter(IntegerTypeHandler.java:26)
	org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:53)
	org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:87)
	org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:93)
	org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:64)
	org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:86)
	org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
	org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)
	org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
	org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
	org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83)
	org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
	org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	java.lang.reflect.Method.invoke(Unknown Source)
	org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:434)
	com.sun.proxy.$Proxy57.selectList(Unknown Source)
	org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:231)
	org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:137)
	org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:75)
	org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
	com.sun.proxy.$Proxy58.findGoodsByName(Unknown Source)
	com.lhm.service.impl.GoodsServiceImpl.findGoodsByName(GoodsServiceImpl.java:78)
	com.lhm.controller.GoodsController.findGoodsByName(GoodsController.java:77)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	java.lang.reflect.Method.invoke(Unknown Source)
	org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
	org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
	org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:806)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:729)
	org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
	org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1084)
	com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
	com.mysql.jdbc.SQLError.createSQLException(SQLError.java:973)
	com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
	com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3688)
	com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3670)
	com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3715)
	com.mysql.jdbc.PreparedStatement.setInt(PreparedStatement.java:3659)
	org.apache.commons.dbcp.DelegatingPreparedStatement.setInt(DelegatingPreparedStatement.java:117)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	java.lang.reflect.Method.invoke(Unknown Source)
	org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:67)
	com.sun.proxy.$Proxy28.setInt(Unknown Source)
	org.apache.ibatis.type.IntegerTypeHandler.setNonNullParameter(IntegerTypeHandler.java:31)
	org.apache.ibatis.type.IntegerTypeHandler.setNonNullParameter(IntegerTypeHandler.java:26)
	org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:53)
	org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:87)
	org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:93)
	org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:64)
	org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:86)
	org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
	org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)
	org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
	org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
	org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83)
	org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
	org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	java.lang.reflect.Method.invoke(Unknown Source)
	org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:434)
	com.sun.proxy.$Proxy57.selectList(Unknown Source)
	org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:231)
	org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:137)
	org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:75)
	org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
	com.sun.proxy.$Proxy58.findGoodsByName(Unknown Source)
	com.lhm.service.impl.GoodsServiceImpl.findGoodsByName(GoodsServiceImpl.java:78)
	com.lhm.controller.GoodsController.findGoodsByName(GoodsController.java:77)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	java.lang.reflect.Method.invoke(Unknown Source)
	org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
	org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
	org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:806)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:729)
	org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
	org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

经过不断的尝试  终于发现了问题所在:

没错  问题就出在这里:

修改前的  GoodsMapper.xml:

修改后的  GoodsMapper.xml:

总结:模糊查询时    like       后面不能用   #{}    获取值,必须    要用    ${}    获取值;当然用#{}也是可以的不过就必须这样写:

LIKE "%"#{goodsName}"%",这样写也是可以的。

你可能感兴趣的:(Mysql)