QUESTION:SSM:Cause: java.sql.SQLSyntaxErrorException: ORA-00933: SQL 命令未正确结束的解决?
ANWSER:
一:问题提出:
使用SSM框架做一个权限后台管理项目时,利用PageHelper插件进行分页查询时,突然出现以下异常:
HTTP Status 500 – Internal Server ErrorType Exception ReportMessage Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException:Description The server encountered an unexpected condition that prevented it from fulfilling the request.Exceptionorg.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException:
### Error querying database. Cause: java.sql.SQLSyntaxErrorException: ORA-00933: SQL 命令未正确结束### The error may exist in com/xy/dao/OrdersDao.java (best guess)
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select *from orders LIMIT ?
### Cause: java.sql.SQLSyntaxErrorException: ORA-00933: SQL 命令未正确结束; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: ORA-00933: SQL 命令未正确结束org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1013)org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:897)javax.servlet.http.HttpServlet.service(HttpServlet.java:635)org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)javax.servlet.http.HttpServlet.service(HttpServlet.java:742)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)Root Causeorg.springframework.jdbc.BadSqlGrammarException:
### Error querying database. Cause: java.sql.SQLSyntaxErrorException: ORA-00933: SQL 命令未正确结束### The error may exist in com/xy/dao/OrdersDao.java (best guess)
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select *from orders LIMIT ?
### Cause: java.sql.SQLSyntaxErrorException: ORA-00933: SQL 命令未正确结束; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: ORA-00933: SQL 命令未正确结束org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:93)org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)com.sun.proxy.$Proxy90.selectList(Unknown Source)org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:137)org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:75)org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)com.sun.proxy.$Proxy94.findAll(Unknown Source)com.xy.service.impl.OrdersServiceImpl.findAll(OrdersServiceImpl.java:28)sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)java.lang.reflect.Method.invoke(Method.java:498)org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)com.sun.proxy.$Proxy97.findAll(Unknown Source)com.xy.controller.OrdersController.findAll(OrdersController.java:32)sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)java.lang.reflect.Method.invoke(Method.java:498)org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189)org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:892)org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797)org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:897)javax.servlet.http.HttpServlet.service(HttpServlet.java:635)org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)javax.servlet.http.HttpServlet.service(HttpServlet.java:742)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)Root Causejava.sql.SQLSyntaxErrorException: ORA-00933: SQL 命令未正确结束oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:439)oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:395)oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:802)oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:436)oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186)oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:521)oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:205)oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:861)oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1145)oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1267)oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3449)oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3550)oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1374)com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:989)org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:63)org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79)org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63)org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:136)org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)com.sun.proxy.$Proxy108.query(Unknown Source)org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)java.lang.reflect.Method.invoke(Method.java:498)org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)com.sun.proxy.$Proxy90.selectList(Unknown Source)org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:137)org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:75)org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)com.sun.proxy.$Proxy94.findAll(Unknown Source)com.xy.service.impl.OrdersServiceImpl.findAll(OrdersServiceImpl.java:28)sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)java.lang.reflect.Method.invoke(Method.java:498)org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)com.sun.proxy.$Proxy97.findAll(Unknown Source)com.xy.controller.OrdersController.findAll(OrdersController.java:32)sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)java.lang.reflect.Method.invoke(Method.java:498)org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189)org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:892)org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797)org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:897)javax.servlet.http.HttpServlet.service(HttpServlet.java:635)org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)javax.servlet.http.HttpServlet.service(HttpServlet.java:742)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)Note The full stack trace of the root cause is available in the server logs.
第一次使用Oracle数据库进行项目的开发,检查写的OrdersDao和OrdersServiceImpl都没有语法错误,在OrdersServiceImpl里去掉分页查询语句可以完美运行:
package com.xy.service.impl;import com.github.pagehelper.PageHelper;
import com.xy.dao.OrdersDao;
import com.xy.domain.Orders;
import com.xy.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;import java.util.List;@Service
@Transactional
public class OrdersServiceImpl implements OrdersService {@Autowiredprivate OrdersDao ordersDao;/*** 查询所有订单* @param pageNum* @param pageSize* @return*/@Overridepublic List<Orders> findAll(int pageNum,int pageSize) {PageHelper.startPage(pageNum,pageSize);return ordersDao.findAll();}
}
二:解决方法:
一开始找了好多相关博客,大部分是说sql语句语法错误。