• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

better option JdbcTemplate.queryForList(query)

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi There,

I am new to springs and needed help / opinion.

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..

Thanks a lot in advance..
Am
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
amol bakre
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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..

Thanks a ton..

Regards,
Am
 
reply
    Bookmark Topic Watch Topic
  • New Topic