• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

JDBCTemplate QueryForList returns wrong value

 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have the following code...



Right now this is failing with the exception...



So it looks like AgentList is made up of LinkedCaseInsensitiveMap objects instead of String objects. Why is this?

Thanks in advance for any help.
 
Ranch Hand
Posts: 686
Netbeans IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the query returns more than one column the List is made up of Map elements.

You might want to try
String agentCode = (String)((Map)agentItr.next()).get("AGENTSURROGATECODE");
 
Jehan Jaleel
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Vyas, that worked.

Do you know why it was returning more than one column, as you can see in my query I am only asking for one column "AGENTSURROGATECODE".
 
Vyas Sanzgiri
Ranch Hand
Posts: 686
Netbeans IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jehan Jaleel wrote:Thanks Vyas, that worked.

Do you know why it was returning more than one column, as you can see in my query I am only asking for one column "AGENTSURROGATECODE".



I dont know the database you are using. Can you try it in your database and see what it returns?
select AGENTSURROGATECODE from SETTLEMENT.AGENT_DETAILS where CYCLE = ?
 
Ranch Hand
Posts: 607
Firefox Browser Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It has nothing to do with the database. A queryForList will return a List of MAP's if you use the format

queryForList(String sql, Object[] args)


To get just a single result you need to use the overloaded;
List queryForList(String sql, Object[] args, Class elementType)

Check out the Javadocs here.
http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/jdbc/core/JdbcOperations.html#queryForList%28java.lang.String,%20java.lang.Object[]%29
 
Vyas Sanzgiri
Ranch Hand
Posts: 686
Netbeans IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh that was basic!

Thanks Sam
 
Ruth Stout was famous for gardening naked. Just like this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic