The thing that i am trying to do is to sue jdbcTemplate's queryForList method to return some data from the DB. This data i pass on to the webpage that expects a lists and takes care of the display etc.
The problem is that the queryForList method is returning to me data in the following form
whereas what i need is just the data. Ofourse i can extract data and stuff, but that i think is dirty and surely there must be some other way to get a List in return (no dao's etc).
Also note i have only one column in the result of my query, stumbled upon SingleColumnRowMapper etc, but did not figure out much how to use them to get a List in return.
Please suggest, preferrably with code example..
Would appreciate a quick response..
If I understand your issue, I think you might want to consider using simpleJdbcDaoSupport. The method Query(String sql, ParameterizedRowMapper<T>, Object... args) should do the trick for you. Use the ParameterizedRowMapper to add the results to your list.
Something like this
If you have to use JdbcTemplate, I would use the method query(String sql, RowMapper mapper). Then you could use the singleColumnRowMapper to map the rows to your list.
I imagine a ParameterizedSingleColumnRowMapper would do the same.
Hope this helps!
Joined: May 21, 2001
O many thanks..i was using JdbcTemplate and i used the query method passing it the SingleColumnRowMapper as you had mentioned in the last, worked well..and was quite easy too, have to nothing but just pass a new instance..
Actually i was using it to get a list so that i can throw that back to the struts2 jsp page (via action etc..) to be displayed in a dropdown list and that is the reason i was looking for just a list..and getting a list and letting struts do all the work seemed a simple way for me to do this..