设为首页 加入收藏

TOP

Mybatis报错TranslatingSQLExceptionwithSQLstate'42000',errorcode'1064',mess问题解决
2018-05-08 06:06:55 】 浏览:239
Tags:Mybatis 报错 TranslatingSQLExceptionwithSQLstate' 42000' errorcode' 1064' mess 问题 解决

今天调试毕设项目的时候,改了mapper的一些sql语句后,一直报这个错:

Mybatis报错Translating SQLException with SQL state '42000', error code '1064', message [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 'LEFT JOIN ah_activity aha ON aha.id = ahua.activity_id
  		LEFT JOIN ah_activity' at line 7]; SQL was [] for task [
### Error querying database.  Cause: 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 'LEFT JOIN ah_activity aha ON aha.id = ahua.activity_id
  		LEFT JOIN ah_activity' at line 7
### The error may exist in crj/ah/ssm/mapper/custom/AhUserActivityMapperCustom.xml
### The error may involve crj.ah.ssm.mapper.custom.AhUserActivityMapperCustom.getCount-Inline
### The error occurred while setting parameters
### SQL: select          count(1)         FROM      ah_user_activity ahua            WHERE  ahua.user_id = 7      LEFT JOIN ah_activity aha ON aha.id = ahua.activity_id     LEFT JOIN ah_activity_space ahas ON ahas.id = ahua.space_id      LEFT JOIN ah_activity_area ahaa ON ahaa.id = ahua.area_id      LEFT JOIN ah_activity_seat ahase ON ahase.id = ahua.seat_id      LEFT JOIN ah_user ahu ON ahu.id = ahua.user_id      LEFT JOIN ah_manager ahm1 ON ahm1.id = ahua.createuser   LEFT JOIN ah_manager ahm2 ON ahm2.id = ahua.updateuser      order by ahua.updatetime desc
### Cause: 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 'LEFT JOIN ah_activity aha ON aha.id = ahua.activity_id
  		LEFT JOIN ah_activity' at line 7
]

检查了好多次,还是觉得语法没有错啊!!!!后来才发现,where 应该放在left join 语句的后面!!!!!

附上sql各语句的执行顺序

(8)SELECT (9)DISTINCT  (11)<Top Num> <select list>
(1)FROM [left_table]
(3)<join_type> JOIN <right_table>
(2)ON <join_condition>
(4)WHERE <where_condition>
(5)GROUP BY <group_by_list>
(6)WITH <CUBE | RollUP>
(7)HAVING <having_condition>
(10)ORDER BY <order_by_list>
逻辑查询处理阶段简介
FROM:对FROM子句中的前两个表执行笛卡尔积(Cartesian product)(交叉联接),生成虚拟表VT1
ON:对VT1应用ON筛选器。只有那些使<join_condition>为真的行才被插入VT2。
OUTER(JOIN):如 果指定了OUTER JOIN(相对于CROSS JOIN 或(INNER JOIN),保留表(preserved table:左外部联接把左表标记为保留表,右外部联接把右表标记为保留表,完全外部联接把两个表都标记为保留表)中未找到匹配的行将作为外部行添加到 VT2,生成VT3.如果FROM子句包含两个以上的表,则对上一个联接生成的结果表和下一个表重复执行步骤1到步骤3,直到处理完所有的表为止。
WHERE:对VT3应用WHERE筛选器。只有使<where_condition>为true的行才被插入VT4.
GROUP BY:按GROUP BY子句中的列列表对VT4中的行分组,生成VT5.
CUBE|ROLLUP:把超组(Suppergroups)插入VT5,生成VT6.
HAVING:对VT6应用HAVING筛选器。只有使<having_condition>为true的组才会被插入VT7.
SELECT:处理SELECT列表,产生VT8.
DISTINCT:将重复的行从VT8中移除,产生VT9.
ORDER BY:将VT9中的行按ORDER BY 子句中的列列表排序,生成游标(VC10).
TOP:从VC10的开始处选择指定数量或比例的行,生成表VT11,并返回调用者。

其实,这种错通常都是sql语句写错,一定是!要细心检查啊!!!

如果你觉得语法没错,那可能你不小心用了保留字


编程开发网
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇ElasticSearch(ES)的简介 下一篇阶梯到高级T-SQL 1级:高级T-SQL..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

最新文章

热门文章

C 语言

C++基础

windows编程基础

linux编程基础

C/C++面试题目