I am using JdbcTemplate
to retrieve a Bean from the db. Here is my method:
public List getTrackerData() {
return List
Should try using Rowmapper like use it as when you query API.
Hope that solves your problem.
JdbcTemplate method
queryForList(String sql, Class<T> 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<T> rowMapper)
as implementation for RowMapper you may use your own, or
jdbcTemplate.query(sql, new BeanPropertyRowMapper<T>(clazz));
so in your case it may be:
public List<Trackerv3Livedata> 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>(Trackerv3Livedata.class));
}
Implementing Bean RowMapper Interface and maprow function solve this problem
public class Mmitrackerv3LivedataMapper implements RowMapper<Mmitrackerv3Livedata> {
@Override
public Mmitrackerv3Livedata mapRow(ResultSet rs, int rowNum)
throws SQLException {
}
And Now I have Change In JDBC Template
List<Mmitrackerv3Livedata> live = jdbcTemplate.query("select * from mmitrackerv3_livedata mlive " +
"join mmitrackerv3_device mdevice on mlive.accountid = mdevice.accountid where mlive.accountid = " +
aid, new Mmitrackerv3LivedataMapper());
Thanks @abhishek
This is happening because, the queryForList method you have used will not support for multiple columns. See the implementation of queryForList from JdbcTemplate
public <T> List<T> More ...queryForList(String sql, Object[] args, Class<T> elementType) throws DataAccessException
{
return query(sql, args, getSingleColumnRowMapper(elementType));
}
The getsingleColumnRowMapper() method creates a new RowMapper for reading result objects from a single column. You can use the method given below instead.
public <T> List<T> query(String sql, Object[] args, RowMapper<T> rowMapper) throws DataAccessException
{
return query(sql, args, new RowMapperResultSetExtractor<T>(rowMapper));
}