aspose file tools*
The moose likes Spring and the fly likes JDBCTemplate QueryForList returns wrong value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "JDBCTemplate QueryForList returns wrong value " Watch "JDBCTemplate QueryForList returns wrong value " New topic
Author

JDBCTemplate QueryForList returns wrong value

Jehan Jaleel
Ranch Hand

Joined: Apr 30, 2002
Posts: 196
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

Joined: Jun 16, 2007
Posts: 686

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");


===Vyas Sanzgiri===
My Blog
Jehan Jaleel
Ranch Hand

Joined: Apr 30, 2002
Posts: 196
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

Joined: Jun 16, 2007
Posts: 686

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

Joined: Feb 08, 2009
Posts: 606

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


Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

Oh that was basic!

Thanks Sam
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBCTemplate QueryForList returns wrong value