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

来源:互联网 发布:局域网未识别的网络 编辑:程序博客网 时间:2024/06/04 18:44

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

原代码是:
<select id="queryTranByCondition" parameterType="map"resultType="Transaction">select tt.id,tu1.name asowner,tt.amountOfMoney,tt.name,tt.expectedClosingDate,tc1.name ascustomerId,dv1.text as stage,dv2.text as type,tt.possibility,dv3.textas source,co1.fullName as contactsId,ma1.name asactivityId,tt.description,tu2.name as createBy,tt.createTime,tu3.nameas editBy,tt.editTime,tt.contactSummary,tt.nextContactTimefromtbl_transaction ttjoin tbl_usertu1 on tt.owner = tu1.idjointbl_customer tc1 ontt.customerId = tc1.idjoin tbl_dictionary_value dv1on tt.stage=dv1.idleft jointbl_dictionary_value dv2 on tt.type=dv2.idleft jointbl_dictionary_value dv3 on tt.source=dv3.idleft jointbl_contacts co1on tt.contactsId=co1.idleft jointbl_marketing_activities ma1 on tt.activityId=ma1.idjoin tbl_user tu2on tt.createBy=tu2.idleft 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 desclimit #{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