Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBCTemplate QueryForList returns wrong value

 
Jehan Jaleel
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.
 
Vyas Sanzgiri
Ranch Hand
Posts: 686
Chrome Netbeans IDE 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
Chrome Netbeans IDE 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 = ?
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • 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
Chrome Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh that was basic!

Thanks Sam
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic