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中后,运行正常.
相关文章推荐
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
- ERROR 1064 (42000): You have an error in your SQL syntax;
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL的问题
- org.hibernate.exception.SQLGrammarException: could not inYou have an error in your SQL syntax;完美解决错误
- com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax;解决办法
- You have an error in your SQL syntax;
- 错误信息:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server ve
- You have an error in your SQL syntax;解决方法
- MySql 执行语句错误 Err] 1064 - 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
- Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL se
- ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
- SQL Error: 1064, SQLState: 42000 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
- com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; che
- ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
- 使用PreparedStatement,出现You have an error in your SQL syntax; check the manual that corresponds to you
- 连接数据库报“You have an error in your SQL syntax”异常的解决
- You have an error in your SQL syntax; 问题的实际解决方法
- FAQ(55):java.sql.SQLException: You have an error in your SQL syntax; check the manual that correspon
- ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
- 使用hibernate架构执行插入操作时You have an error in your SQL syntax;