SSM中通过mybatis反向生成,sql报错,报500错误

错误信息如下

HTTP Status 500 - Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException:
type Exception report

message Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException:

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException:

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 'like, forward, collection,

date

from t_rank

’ at line 4

The error may exist in file [D:\Eclipse.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\hedaluntan\WEB-INF\classes\mapper\RankMapper.xml]

The error may involve com.hbu.dao.RankMapper.selectByExample-Inline

The error occurred while setting parameters

SQL: select id, uid, image, nick_name, contribution, visit, grade, fans, like, forward, collection, date from t_rank order by contribution 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 'like, forward, collection,

date

from t_rank

’ at line 4
; 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 'like, forward, collection,
date

from t_rank

’ at line 4
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:979)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858)
javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

org.springframework.jdbc.BadSqlGrammarException:

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 'like, forward, collection,

date

from t_rank

’ at line 4

The error may exist in file [D:\Eclipse.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\hedaluntan\WEB-INF\classes\mapper\RankMapper.xml]

The error may involve com.hbu.dao.RankMapper.selectByExample-Inline

The error occurred while setting parameters

SQL: select id, uid, image, nick_name, contribution, visit, grade, fans, like, forward, collection, date from t_rank order by contribution 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 'like, forward, collection,

date

from t_rank

’ at line 4
; 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 'like, forward, collection,
date

from t_rank

’ at line 4
org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:231)
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:74)
org.mybatis.spring.SqlSessionTemplate S q l S e s s i o n I n t e r c e p t o r . i n v o k e ( S q l S e s s i o n T e m p l a t e . j a v a : 399 ) c o m . s u n . p r o x y . SqlSessionInterceptor.invoke(SqlSessionTemplate.java:399) com.sun.proxy. SqlSessionInterceptor.invoke(SqlSessionTemplate.java:399)com.sun.proxy.Proxy12.selectList(Unknown Source)
org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:205)
org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:122)
org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:64)
org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
com.sun.proxy.$Proxy23.selectByExample(Unknown Source)
com.hbu.service.impl.RankServiceImpl.select(RankServiceImpl.java:31)
com.hbu.web.RankController.contribution(RankController.java:63)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858)
javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root 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 'like, forward, collection,
date

from t_rank

’ at line 4
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
java.lang.reflect.Constructor.newInstance(Unknown Source)
com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
com.mysql.jdbc.Util.getInstance(Util.java:387)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:941)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3870)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3806)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2470)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2617)
com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2550)
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1192)
com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:989)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59)
com.sun.proxy. P r o x y 40. e x e c u t e ( U n k n o w n S o u r c e ) o r g . a p a c h e . i b a t i s . e x e c u t o r . s t a t e m e n t . P r e p a r e d S t a t e m e n t H a n d l e r . q u e r y ( P r e p a r e d S t a t e m e n t H a n d l e r . j a v a : 62 ) o r g . a p a c h e . i b a t i s . e x e c u t o r . s t a t e m e n t . R o u t i n g S t a t e m e n t H a n d l e r . q u e r y ( R o u t i n g S t a t e m e n t H a n d l e r . j a v a : 78 ) o r g . a p a c h e . i b a t i s . e x e c u t o r . S i m p l e E x e c u t o r . d o Q u e r y ( S i m p l e E x e c u t o r . j a v a : 62 ) o r g . a p a c h e . i b a t i s . e x e c u t o r . B a s e E x e c u t o r . q u e r y F r o m D a t a b a s e ( B a s e E x e c u t o r . j a v a : 303 ) o r g . a p a c h e . i b a t i s . e x e c u t o r . B a s e E x e c u t o r . q u e r y ( B a s e E x e c u t o r . j a v a : 154 ) o r g . a p a c h e . i b a t i s . e x e c u t o r . C a c h i n g E x e c u t o r . q u e r y ( C a c h i n g E x e c u t o r . j a v a : 102 ) o r g . a p a c h e . i b a t i s . e x e c u t o r . C a c h i n g E x e c u t o r . q u e r y ( C a c h i n g E x e c u t o r . j a v a : 82 ) s u n . r e f l e c t . N a t i v e M e t h o d A c c e s s o r I m p l . i n v o k e 0 ( N a t i v e M e t h o d ) s u n . r e f l e c t . N a t i v e M e t h o d A c c e s s o r I m p l . i n v o k e ( U n k n o w n S o u r c e ) s u n . r e f l e c t . D e l e g a t i n g M e t h o d A c c e s s o r I m p l . i n v o k e ( U n k n o w n S o u r c e ) j a v a . l a n g . r e f l e c t . M e t h o d . i n v o k e ( U n k n o w n S o u r c e ) o r g . a p a c h e . i b a t i s . p l u g i n . I n v o c a t i o n . p r o c e e d ( I n v o c a t i o n . j a v a : 49 ) c o m . g i t h u b . p a g e h e l p e r . S q l U t i l . p r o c e s s P a g e ( S q l U t i l . j a v a : 401 ) c o m . g i t h u b . p a g e h e l p e r . S q l U t i l . p r o c e s s P a g e ( S q l U t i l . j a v a : 374 ) c o m . g i t h u b . p a g e h e l p e r . P a g e H e l p e r . i n t e r c e p t ( P a g e H e l p e r . j a v a : 254 ) o r g . a p a c h e . i b a t i s . p l u g i n . P l u g i n . i n v o k e ( P l u g i n . j a v a : 61 ) c o m . s u n . p r o x y . Proxy40.execute(Unknown Source) org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:62) org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:78) org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62) org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:303) org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:154) org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:102) org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:82) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) java.lang.reflect.Method.invoke(Unknown Source) org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49) com.github.pagehelper.SqlUtil._processPage(SqlUtil.java:401) com.github.pagehelper.SqlUtil.processPage(SqlUtil.java:374) com.github.pagehelper.PageHelper.intercept(PageHelper.java:254) org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) com.sun.proxy. Proxy40.execute(UnknownSource)org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:62)org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:78)org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:303)org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:154)org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:102)org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:82)sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)sun.reflect.NativeMethodAccessorImpl.invoke(UnknownSource)sun.reflect.DelegatingMethodAccessorImpl.invoke(UnknownSource)java.lang.reflect.Method.invoke(UnknownSource)org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49)com.github.pagehelper.SqlUtil.processPage(SqlUtil.java:401)com.github.pagehelper.SqlUtil.processPage(SqlUtil.java:374)com.github.pagehelper.PageHelper.intercept(PageHelper.java:254)org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)com.sun.proxy.Proxy38.query(Unknown Source)
org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:120)
org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:113)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.mybatis.spring.SqlSessionTemplate S q l S e s s i o n I n t e r c e p t o r . i n v o k e ( S q l S e s s i o n T e m p l a t e . j a v a : 386 ) c o m . s u n . p r o x y . SqlSessionInterceptor.invoke(SqlSessionTemplate.java:386) com.sun.proxy. SqlSessionInterceptor.invoke(SqlSessionTemplate.java:386)com.sun.proxy.Proxy12.selectList(Unknown Source)
org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:205)
org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:122)
org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:64)
org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
com.sun.proxy.$Proxy23.selectByExample(Unknown Source)
com.hbu.service.impl.RankServiceImpl.select(RankServiceImpl.java:31)
com.hbu.web.RankController.contribution(RankController.java:63)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858)
javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/8.0.9 logs.

Apache Tomcat/8.0.9

在这里插入图片描述
报错原因:数据库中字段名取了sql关键字

可以看到,错误显示sql查询语法错了问题,这里是因为我数据库中字段名使用了like关键字,所以报错

总结:数据库中字段名一定要防止取到关键字

猜你喜欢

转载自blog.csdn.net/qq_45590494/article/details/105741420