博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mybatis paramType String Error
阅读量:6449 次
发布时间:2019-06-23

本文共 7817 字,大约阅读时间需要 26 分钟。

我这么写的

然后就报了异常:

org.springframework.dao.TransientDataAccessResourceException: ### Error querying database.  Cause: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).### The error may exist in file [/Users/xxx/Documents/generation/2017/workspaces/ideasp/xxx/target/classes/mappers/ShhIndexMapper.xml]### The error may involve com.xxx.index.dao.ShhIndexMapper.getxxx-Inline### The error occurred while setting parameters### SQL: select a.player_id as playerId,c.player_name as playerName,sum(a.k_index) as kIndex     from shh_index a     left join shh_player c on a.player_id = c.id     where date(a.updated_date) = DATE("?")     group by a.player_id     order by sum(a.k_index) desc### Cause: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).; 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.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:108)    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:73)    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)    at com.sun.proxy.$Proxy43.selectList(Unknown Source)    at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:198)    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.$Proxy47.getHotPlayersByDate(Unknown Source)    at com.shh.index.ShhTest.testMineSqlMapper(ShhTest.java:34)    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 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:254)    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)    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.intellij.rt.execution.application.AppMain.main(AppMain.java:147)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:963)    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:896)    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:885)    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)    at com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3321)    at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3306)    at com.mysql.jdbc.PreparedStatement.setString(PreparedStatement.java:4021)    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.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 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:62)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:498)    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)    ... 40 more

原因是:

写like语句的时候 一般都会写成 like '% %'

在mybatis里面写就是应该是 like  '%${name} %' 而不是 '%#{name} %'  

${name} 是不带单引号的,而#{name} 是带单引号的

去掉双引号,直接where date(a.updated_date) = DATE(#{dateStr,jdbcType=VARCHAR})

转载于:https://www.cnblogs.com/guazi/p/6792758.html

你可能感兴趣的文章
隐藏控制台窗口的方法
查看>>
【转】Linux下svn常用指令
查看>>
test
查看>>
前端学习网站推荐
查看>>
Windows Phone 获取网络类型(GSM/CDMA/WIFI/Ethernet)
查看>>
006、容器 What、Why、How(2018-12-21 周五)
查看>>
LeetCode算法题-Linked List Cycle(Java实现)
查看>>
nlp Task1
查看>>
基于reflectasm打造自己的通用bean工具
查看>>
ReactiveCocoa & MVVM 学习总结一
查看>>
MVVM
查看>>
捕捉深市最后三分钟的个股玄机
查看>>
docker jenkins使用(二)
查看>>
简单BootLoader
查看>>
oracle库和表空间
查看>>
linux高编进程------进程分配
查看>>
Docker的基本操作
查看>>
hdu2276 快速矩阵幂
查看>>
vim制表符占位个数修改
查看>>
JSP内置对象值out对象及其它的一些常见方法
查看>>