您的 SQL 语法有误;查看与您的 MySQL 服务器版本对应的手册,了解在 'order 附近使用的正确语法
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 'order
是什么导致了这个异常,我在 UserController
中使用了类似的方法并且效果很好。 SQL table 与实体 类 的映射是否错误?
我无法存储数据,也无法从中检索任何内容。它一直给我同样的错误,最初我虽然我的纬度和经度可能是错误的但后来我尝试插入一个简单的 user_id
但也被拒绝了。
控制器
@Autowired
OrderMapper orderMapper;
@ResponseBody
@RequestMapping(value = "/getOrder", method = RequestMethod.POST)
public Order PlaceOrder()
{
Order order = new Order();
order.setUserId(1);
orderMapper.insert(order);
return order;
}
OrderMapper
<insert id="insert" parameterType="com.mena.api.entity.Order">
insert into order (order_id, user_id, start_latitude,
start_logitude, end_latitude, end_logitude,
total_distance, type, cost,
create_time, start_address, end_address,
user_id2)
values (#{orderId,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, #{startLatitude,jdbcType=DECIMAL},
#{startLogitude,jdbcType=DECIMAL}, #{endLatitude,jdbcType=DECIMAL}, #{endLogitude,jdbcType=DECIMAL},
#{totalDistance,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}, #{cost,jdbcType=VARCHAR},
#{createTime,jdbcType=TIMESTAMP}, #{startAddress,jdbcType=VARCHAR}, #{endAddress,jdbcType=VARCHAR},
#{userId2,jdbcType=INTEGER})</insert>
和SQL Table信息
错误日志
</pre><p><b>Root Cause</b></p><pre>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 'order
where order_id = 1' at line 6
### The error may exist in file [\khadim\khadimApi\khadimApi\target\khadminapi\WEB-INF\classes\mybatis\OrderMapper.xml]
### The error may involve com.mena.api.mapper.OrderMapper.selectByPrimaryKey-Inline
### The error occurred while setting parameters
### SQL: select 'true' as QUERYID, order_id, user_id, start_latitude, start_logitude, end_latitude, end_logitude, total_distance, type,
cost, create_time, start_address, end_address, user_id2 from order where order_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 'order
where order_id = 1' at line 6
; 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 'order
where order_id = 1' at line 6
org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:235)
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75)
org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:447)
com.sun.proxy.$Proxy35.selectOne(Unknown Source)
org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:167)
org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:82)
org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
com.sun.proxy.$Proxy36.selectByPrimaryKey(Unknown Source)
com.mena.api.controller.OrderController.PlaceOrder(OrderController.java:34)
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)
order 是 MySql 中的保留字,这就是为什么您的 select ... from order
可能因该异常而失败。如果 order 确实是您数据库中的 table 名称,您可以按如下方式转义它:
select ... from `order` ...
或者更好的方法是使用非保留的 table 名称,例如 'orders'.
是什么导致了这个异常,我在 UserController
中使用了类似的方法并且效果很好。 SQL table 与实体 类 的映射是否错误?
我无法存储数据,也无法从中检索任何内容。它一直给我同样的错误,最初我虽然我的纬度和经度可能是错误的但后来我尝试插入一个简单的 user_id
但也被拒绝了。
控制器
@Autowired
OrderMapper orderMapper;
@ResponseBody
@RequestMapping(value = "/getOrder", method = RequestMethod.POST)
public Order PlaceOrder()
{
Order order = new Order();
order.setUserId(1);
orderMapper.insert(order);
return order;
}
OrderMapper
<insert id="insert" parameterType="com.mena.api.entity.Order">
insert into order (order_id, user_id, start_latitude,
start_logitude, end_latitude, end_logitude,
total_distance, type, cost,
create_time, start_address, end_address,
user_id2)
values (#{orderId,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, #{startLatitude,jdbcType=DECIMAL},
#{startLogitude,jdbcType=DECIMAL}, #{endLatitude,jdbcType=DECIMAL}, #{endLogitude,jdbcType=DECIMAL},
#{totalDistance,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}, #{cost,jdbcType=VARCHAR},
#{createTime,jdbcType=TIMESTAMP}, #{startAddress,jdbcType=VARCHAR}, #{endAddress,jdbcType=VARCHAR},
#{userId2,jdbcType=INTEGER})</insert>
和SQL Table信息
错误日志
</pre><p><b>Root Cause</b></p><pre>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 'order
where order_id = 1' at line 6
### The error may exist in file [\khadim\khadimApi\khadimApi\target\khadminapi\WEB-INF\classes\mybatis\OrderMapper.xml]
### The error may involve com.mena.api.mapper.OrderMapper.selectByPrimaryKey-Inline
### The error occurred while setting parameters
### SQL: select 'true' as QUERYID, order_id, user_id, start_latitude, start_logitude, end_latitude, end_logitude, total_distance, type,
cost, create_time, start_address, end_address, user_id2 from order where order_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 'order
where order_id = 1' at line 6
; 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 'order
where order_id = 1' at line 6
org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:235)
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75)
org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:447)
com.sun.proxy.$Proxy35.selectOne(Unknown Source)
org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:167)
org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:82)
org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
com.sun.proxy.$Proxy36.selectByPrimaryKey(Unknown Source)
com.mena.api.controller.OrderController.PlaceOrder(OrderController.java:34)
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)
order 是 MySql 中的保留字,这就是为什么您的 select ... from order
可能因该异常而失败。如果 order 确实是您数据库中的 table 名称,您可以按如下方式转义它:
select ... from `order` ...
或者更好的方法是使用非保留的 table 名称,例如 'orders'.