MyBatis错误收集

1、在用动态SQL老一个There is no getter for property named 'id' in 'class java.lang.Integer错误

<select id="queryUser" parameterType="Integer" resultType="com.accp.TestMybatis.dto.User">
 select * from scott.users
 <if test="id!=null"> 
   where id = #{id}
 </if>
</select>
<!--但是把if去掉如:-->
<select id="queryUser" parameterType="Integer" resultType="com.accp.TestMybatis.dto.User">
   select * from scott.users where id = #{id}
</select>
<!--又正常,非常蛋疼。-->

解决方法:

将<if test="id!=null">改为
<if test="_parameter!=null">  
    where id = #{_parameter}
</if>

问题来源:http://bbs.csdn.net/topics/370173955?page=1

2、在mybatis中使用select top #{top}  *  from tb 语句出现“@P0' 附近有语法错误"。

问题分析:

   语句编译后#{}是预处理状态,在Java中对数据库查询时经常使用“Select Top ? * From 表名 Where 列名 = 
 ?”的SQL语句,此时的问号是PreparedStatement预编译对象的参数占位符,需要使用setXX()系列方法对其赋值后再执行。但是,Top后面是不允许使用问号占位符的,此处的错误就是由此引起的。

解决方法:

   语句修改为:select top ${top}  *  from tb 

问题来源:http://ekekyn.blog.163.com/blog/static/313887320122159632536/

3、使用SQL批量添加数据时,出现The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Too many parameters were provided in this RPC request. The maximum is 2100.   

SQL语句:

INSERT INTO [TABLE]([FIELD],[FIELD]...)VALUES([VALUE],[VALUE]...),([VALUE],[VALUE]...)...

解决方法:

public void batchInsert(List<Course> courses) {
   for(int i = 0,s = 0; i < courses.size()/100;i++,s+=100){ 
	sqlSessionTemplate.insert("com.netDragon.domain.Course.batchInsert", courses.subList(s, s+100));
   }
   if(courses.size() - courses.size()/100*100 > 0)
	sqlSessionTemplate.insert("com.netDragon.domain.Course.batchInsert", courses.subList(courses.size()/100*100,courses.size()));
   }




转载于:https://my.oschina.net/u/1425545/blog/272037

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值