[英]Wiered mysqlSyntaxErrorException with mybatis-spring
我的mybatis-spring面临着一个非常棘手的问题,它不断给我的mysql语法异常
bad SQL grammar []; nested exception is 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 'CREATE TEMPORARY TABLE IF NOT EXISTS temptable AS(
select c.tmpid,h.val' at line 4
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:231)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:368)
at com.sun.proxy.$Proxy20.selectOne(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:163)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:95)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:40)
at com.sun.proxy.$Proxy23.getValue(Unknown Source)
at com.mypackage.service.getValue(service.java:260)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.cache.interceptor.CacheInterceptor$1.invoke(CacheInterceptor.java:52)
at org.springframework.cache.interceptor.CacheAspectSupport.invokeOperation(CacheAspectSupport.java:317)
at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:350)
at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:299)
at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
下面是查询:
CREATE TEMPORARY TABLE IF NOT EXISTS temptable AS(
select c.tmpid,h.value from xyz c
left join pqr h
on h.tmpid = c.tmpid
where h.date = (select max(date) from abc where tmpid = c.tmpid)
);
select * from temptable;
drop table temptable;
仅当我在服务器上部署时才会发生这种情况。 在当地工作正常,没有任何问题。
在本地上,我正在使用服务器版本:5.5.27-log MySQL Community Server(GPL),但在服务器上其服务器版本:5.5.44-0 + deb7u1(Debian)
我怀疑服务器版本问题,但未找到任何内容。
以下是我的jar版本:mybatis:3.3.0 mybatis-spring:1.2.3 mysql:5.1.36
从某种意义上讲,它的工作方式很混乱,因此它在本地的工作效果非常好,因此推出了无效语法的可能性。
我也尝试用相同的查询创建.sql文件,并在服务器上的mysql命令行上将其触发,它返回完美的结果。
有人有指针吗?
mybatis抛出的异常将我带到了不同的方向。 我错过了在服务器上添加的连接URL的问题。 需要将?allowMultiQueries = true设置为允许执行多个语句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.