com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax

       这个错误是dao层xml里面mysql语句格式错误,找错误的方法是看提示错误语句中的near后面的语句,查找这里的错误.我这里出现的错误是传入参数类型的错误.

原代码是:
<select id="queryTranByCondition" parameterType="map"
		resultType="Transaction">
		select tt.id,tu1.name as
		owner,tt.amountOfMoney,tt.name,tt.expectedClosingDate,tc1.name as
		customerId,dv1.text as stage,dv2.text as type,tt.possibility,dv3.text
		as source,co1.fullName as contactsId,ma1.name as
		activityId,tt.description,tu2.name as createBy,
		tt.createTime,tu3.name
		as editBy,tt.editTime,tt.contactSummary,tt.nextContactTime
		from
		tbl_transaction tt
		join tbl_user
		tu1 on tt.owner = tu1.id
		join
		tbl_customer tc1 on
		tt.customerId = tc1.id
		join tbl_dictionary_value dv1
		on tt.stage=dv1.id
		left join
		tbl_dictionary_value dv2 on tt.type=dv2.id
		left join
		tbl_dictionary_value dv3 on tt.source=dv3.id
		left join
		tbl_contacts co1
		on tt.contactsId=co1.id
		left join
		tbl_marketing_activities ma1 on tt.activityId=ma1.id
		join tbl_user tu2
		on tt.createBy=tu2.id
		left join tbl_user tu3 on tt.editBy=tu3.id
		  <where>
			<if test="owner!=null and owner!=''">
				and tu1.name like "%" #{owner} "%"
			</if>
			<if test="name!=null and name!=''">
				and tt.name like "%" #{name} "%"
			</if>
			<if test="amountOfMoney!=null and amountOfMoney!=''">
				and tt.amountOfMoney like "%" #{amountOfMoney} "%"
			</if>
			<if test="customerName!=null and customerName!=''">
				and tc1.name like "%" #{customerName} "%"
			</if>
			<if test="stage!=null and stage!=''">
				and tt.stage = #{stage} 
			</if>
			<if test="type!=null and type!=''">
				and tt.type = #{type} 
			</if>
			<if test="source!=null and source!=''">
				and tt.source = #{source} 
			</if>
			<if test="contactsName!=null and contactsName!=''">
				and co1.fullName like "%" #{contactsName} "%"
			</if>
		</where> 
		order by createTime desc
		limit #{beginNo},#{pageCount}
	</select>
错误的信息是:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''0','5'' at line 31
可以看到near后面提示的是传入的limit 后面两个参数错误,查看了后台代码,map直接存储了从前台传到后台的字符串类型的pageNo和pageCount;而mysql中limit后面需要传入的是整数int类型.所以将代码转换为int类型后存储到map中后,运行正常.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值