我正在尝试使用 ResultSetExtractor 向数据库发送一条 SQL 语句,但该方法卡在了行上l.setId(resultSet.getInt("Id"));
。
这是我的错误信息:
“消息”:“PreparedStatementCallback;SQL [SELECT Cities.Name FROM city INNER JOIN Notes on Cities.Id = Notes.CitiesId WHERE Notes.CitiesId = ? AND Notes.id = ?] 的未分类 SQLException;SQL 状态 [S0022];错误代码 [0];未找到列 'Id'。;嵌套异常是 java.sql.SQLException:未找到列 'Id'。",
该Cities
表有 3 列,分别命名为Id
、Name
和Code
。我在 Workbench 中检查了我的 SQL 语句,它是正确的。我的代码有什么问题?
public List<Cities> GetCity(String CityId, String NoteId) {
final String sql = "SELECT Cities.Name FROM cities INNER JOIN Notes on Cities.Id = Notes.CitiesId WHERE Notes.CitiesId = ? AND Notes.id = ?";
final List<Cities> cityList = jdbcTemplate.query(sql, new ResultSetExtractor<List<Cities>>() {
@Override
public List<Cities> extractData(ResultSet resultSet) throws SQLException, DataAccessException {
List<Cities> list = new ArrayList<Cities>();
while (resultSet.next()) {
Cities l = new Cities();
l.setId(resultSet.getInt("Id"));
l.setName(resultSet.getString("Name"));
l.setCode(resultSet.getString("Code"));
list.add(l);
}
System.out.println(list);
return list;
}
}, CityId, NoteId);
return cityList;
}