• 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
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

JDBCTemplate QueryForList returns wrong value

 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh that was basic!

Thanks Sam
 
Look ma! I'm selling my stuff!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic