gpt4 book ai didi

java - 我们如何修复“java.sql.SQLSyntaxErrorException :

转载 作者:行者123 更新时间:2023-11-29 06:31:18 29 4
gpt4 key购买 nike

我想通过 api 显示订单列表,但 DAO SQLSyntaxErrorException 中出现错误。

@RequestMapping("list")
public String getAllOrders() {
//APIResponse response=new APIResponse();
List<OrderBeans> orderList = orderDao.selectAll();

return new Gson().toJson(orderList);
}
public List<OrderBeans> selectAll() {
System.out.println("DAO => " + jdbcTemplate);
List<OrderBeans> orders = null;
String query = "select * from " + TABLE_ORDER +"";
try {
orders = jdbcTemplate.query(query, new OrderRowMapper());
} catch (EmptyResultDataAccessException | IncorrectResultSetColumnCountException e) {

}
return orders;
}
3-May-2019 15:01:15.997 SEVERE [http-nio-8084-exec-109] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [dispatcher] in context with path [/Grocery] threw exception [Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [select * from order]; nested exception is java.sql.SQLSyntaxErrorException: 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' at line 1] with root cause
java.sql.SQLSyntaxErrorException: 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' at line 1

最佳答案

我在这里推测您的错误是由于您的 SQL 表被称为 ORDER 造成的,这当然是几乎所有 SQL 版本中的保留关键字。您应该始终避免使用保留关键字命名表和列。作为解决方法,您可以按如下方式构建查询,在表名称周围放置反引号:

String query = "select * from `" + TABLE_ORDER + "`";

但是,在您有机会修复数据模型之前,上述内容只能被视为临时解决方案。

关于java - 我们如何修复“java.sql.SQLSyntaxErrorException :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56110198/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com