I have my class that is something like this:
public class DBConection extends SimpleJdbcDaoSupport implements ElectionsDao{
public List<String> getDates(){
try{
String sql = "SELECT electiondate FROM electiondate";
List<String> dates = new ArrayList<String>();
dates = getSimpleJdbcTemplate().query(sql,
ParameterizedBeanPropertyRowMapper.newInstance(String.class));
System.out.println(dates.size());
System.out.println(dates.get(0));
return dates;
}catch(DataAccessException ex){
throw new RuntimeException(ex);
}
}
}
I’m trying to get the values from the SQL statement and then add them as String objects to a List but when I run my project it returns the number of values but all in blank. Does anybody know why? I have my configuration file and everything. I think that it has to be a problem defining the query(). I’m using the Spring framework.
I have figure it out how to do it.
Here’s how I did it:
I had to do a “StringRowMapper” inner class for this to work.
Hope it helps you!