IncorrectResultSetColumnCountException: Incorrect column count: expected 1, actual 38

前端 未结 4 1870
刺人心
刺人心 2021-02-12 22:18

I am using JdbcTemplate to retrieve a Bean from the db. Here is my method:

public List  getTrackerData() {
    return List         


        
4条回答
  •  失恋的感觉
    2021-02-12 22:57

    JdbcTemplate method

    queryForList(String sql, Class elementType)
    

    is useful for one-column-queries, you may only specify the column type. If you need more than one column in ResultSet, it's more accurate to use

    query(String sql, RowMapper rowMapper)
    

    as implementation for RowMapper you may use your own, or

    jdbcTemplate.query(sql, new BeanPropertyRowMapper(clazz));
    

    so in your case it may be:

    public List getTrackerData() {
        String sql = "SELECT * FROM mmitrackerv3_livedata mlive " +
                     "JOIN mmitrackerv3_device mdevice ON mlive.accountid = " +
                     "mdevice.accountid WHERE mlive.accountid = " + aid;
    
        return jdbcTemplate.query(sql,
            new BeanPropertyRowMapper(Trackerv3Livedata.class));
    }
    

提交回复
热议问题