您的位置:首页 > 数据库 > MySQL

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

2017-10-07 18:56 423 查看

       这个错误是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中后,运行正常.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐