java使用mybatis报错之Mysql查询表字段带关键字

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 'condition conditions, createnum, send_num, use_num, send_start_time, 
    send_e' at line 3
### The error may exist in file [D:\workspace\SpingWind\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\serverPub\WEB-INF\classes\mapper\mysql\mall\FCouponMapper.xml]
### The error may involve mapper.mysql.mall.FCouponMapper.selectByPrimaryKey-Inline
### The error occurred while setting parameters
### SQL: select            id, name , type, money, condition conditions, createnum, send_num, use_num, send_start_time,      send_end_time, use_start_time, use_end_time, add_time, remark, status , img_url, send_condition,      validity         from f_coupon     where id = ?
### 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 'condition conditions, createnum, send_num, use_num, send_start_time, 
    send_e' at line 3
; 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 'condition conditions, createnum, send_num, use_num, send_start_time, 
    send_e' at line 3
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:973)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	com.hbesct.core.controller.GrantedFilter.doFilter(GrantedFilter.java:136)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

------------------------------------------------------------------------------------

我们的SQL查询表字段中带有以关键字命名的字段时,Mybatis会报错,则查询字段需要使用特殊符号将其引起来(·),实例如下:

select id,name,condition,status,age from user;

修改后的SQL:

select id,`name`,`condition`,`status`,age from user;

 

你可能感兴趣的:(数据库,java,mysql,关键字,查询)