@Service--類
@Autowired
JdbcTemplate jdbcTemplate;
public List<Map<String, Object>> amount(int id) {
Food food = new Food();
String query = " SELECT id, sum(breakfast lunch dinner) as amount FROM food WHERE id =?";
int Id = food.getId();
String breakfast = food.getBreakfast();
String lunch = food.getLunch();
String dinner = food.getDinner();
return jdbcTemplate.queryForList(query, Id, breakfast, lunch, dinner);
}
**iam trying to sum values which is present in my table **
java.sql.SQLException:引數索引超出范圍(2 > 引數數量,即 1)。在 com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) ~[mysql-connector-j-8.0.31.jar:8.0.31] 在 com.mysql.cj.jdbc.exceptions。 SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-j-8.0.31.jar:8.0.31] at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) ~ [mysql-connector-j-8.0.31.jar:8.0.31] 在 com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) ~[mysql-connector-j-8.0.31. jar:8.0.31] 在 com.mysql.cj.jdbc.ClientPreparedStatement.checkBounds(ClientPreparedStatement.java:1345) ~[mysql-connector-j-8.0.31.jar:8.0.31] 在 com.mysql.cj。 jdbc.ClientPreparedStatement.getCoreParameterIndex(ClientPreparedStatement.java:1358) ~[mysql-connector-j-8.0.31.jar:8.0.31] at com.mysql.cj.jdbc。
uj5u.com熱心網友回復:
在您的查詢中有一個 unique ?,這意味著該jdbcTemplate.queryForList方法只接受一個值,我假設它是變數 id。因此,要么您忘記在查詢中添加其他條件,要么您正在傳遞其他值。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/524820.html
