0

I'm trying to use ResultSetExtractor to send a SQL statement to the database, but the method is getting stuck at the line l.setId(resultSet.getInt("Id"));.

This is my error message:

"message": "PreparedStatementCallback; uncategorized SQLException for SQL [SELECT Cities.Name FROM cities INNER JOIN Notes on Cities.Id = Notes.CitiesId WHERE Notes.CitiesId = ? AND Notes.id = ?]; SQL state [S0022]; error code [0]; Column 'Id' not found.; nested exception is java.sql.SQLException: Column 'Id' not found.",

The Cities table has 3 columns named Id, Name, and Code. I checked my SQL statement in Workbench and it is correct. What's wrong with my code?

 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;
    }
Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49

0 Answers0