You're missing something as you're creating a new Month() and then calling
result.setMonth(m); however, I don't see the code for setMonth.
I think this is an issue with a getter/setting rather than an issue with
DBUtils.
Can you add debug statements and see what the calls to rs.
getString("monthAbbreviation"), rs.getString("monthName"), and
rs.getInt("monthNo")
return?
Bill-
On Sun, Mar 10, 2013 at 11:32 AM, Betty User <[email protected]> wrote:
> Hello,
>
> I am creating MVC web application in Spring.
>
> With this Java code I'm trying to convert resultset int JavaBeans.
>
> List<MonthOrderCount> retList = new LinkedList<>();
> BasicRowProcessor brp = new BasicRowProcessor(new
> MonthOrderCountHandler());
> BeanListHandler<MonthOrderCount> m = new
> BeanListHandler<>(MonthOrderCount.class, brp);
> retList.addAll(queryRunner.query(sql, m, Util.utilDateToSqlDate(dateFrom),
> Util.utilDateToSqlDate(dateTo)));
>
> But it doesn't work for me - List is filled with objects (MonthOrderCount),
> value orderCount is correct but month variable is null.
>
> My implementation of MonthOrderCountHandler class:
>
> public class MonthOrderCountHandler extends BeanProcessor {
>
> @Override
> public Object toBean(ResultSet rs, Class type) throws SQLException {
>
> // Year
> Year year = new Year();
> year.setYearNo(rs.getInt("yearNo"));
> year.setYear4(rs.getString("year4"));
> year.setYear2(rs.getString("year2"));
>
> // Quarter
> Quarter quarter = new Quarter();
> quarter.setQuarterNo(rs.getInt("quarterNo"));
>
> // Month
> Month m = new Month();
> m.setYear(year);
> m.setQuarter(quarter);
> m.setMonthAbbreviation(rs.getString("monthAbbreviation"));
> m.setMonthName(rs.getString("monthName"));
> m.setMonthNo(rs.getInt("monthNo"));
>
> // Final bean
> MonthOrderCount result = new MonthOrderCount();
> result.setMonth(m);
> result.setOrderCount(rs.getInt("orderCount"));
>
> return result;
>
> }
> }
>
> Structure of my domain objects is:
>
> MonthOrderCount class:
>
> public class MonthOrderCount {
> private Month month;
> private int orderCount;
> }
> Month class:
>
> public class Month {
> private Quarter quarter;
> private Year year;
> private int monthNo;
> private String monthName;
> private String monthAbbreviation;
> }
>
> Quarter class:
>
> public class Quarter {
> private int quarter;
> private String abbreviation;
> }
>
> Year class:
>
> public class Year {
> private int yearNo;
> private String year2;
> private String year4;
> }
>
> I cannot use standard method:
>
> ResultSetHandler<List<MonthOrderCount>> listUrlHandler = new
> BeanListHandler<>(MonthOrderCount.class);
>
> beacuse instances of MonthOrderCount class contains another objects created
> from values from a row and I need to create them.
>
> What am I doing wrong with MonthOrderCountHandler class?
>
> Thanks.
>