aspose file tools*
The moose likes Spring and the fly likes Inefficiency in queryForList(..) methods of JDBCTemplate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Inefficiency in queryForList(..) methods of JDBCTemplate " Watch "Inefficiency in queryForList(..) methods of JDBCTemplate " New topic
Author

Inefficiency in queryForList(..) methods of JDBCTemplate

Talib Jockey
Greenhorn

Joined: Aug 06, 2003
Posts: 22
Why do queryForList(..) methods in the JDBCTemplate class return a List with Maps where the Key=Column Name and Value=Column Value? As I understand it leads to a lot of repetition of column names in the maps. Basically all the Maps will have the same column names, what is the rationale behind returning so many Maps with similar Keys?

Any insight will be appreciated.

Regards,
Talib


SCJP 1.4 - 97%<br />SCWCD 1.4 - In Progress
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You'd probably want to ask on a Spring list, but I'd imagine it's so each item in the list an be accessed in the same way, and it provides a "common-sense" way of accessing data.
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Hm, I don't quite understand what you mean. Using a map is a way to store result data.
If we don't use map we could use domain object but that requires data mapping.


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
Talib Jockey
Greenhorn

Joined: Aug 06, 2003
Posts: 22
So do you think it is a good idea to use this data structure in my application? I want to use something generic, do you see an issue with memory and efficiency because of the column names are repeated multiple times???

Regards,
Talib
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Map is generic enough, could you please to suggest something more generic?

Regarding inefficiency, the implementation could create only one String object and make many instances of Map refer to the same String object. So it's not inefficiency.
G.Sathish kumar
Ranch Hand

Joined: Jul 27, 2009
Posts: 84
Talib Jockey wrote:Why do queryForList(..) methods in the JDBCTemplate class return a List with Maps where the Key=Column Name and Value=Column Value? As I understand it leads to a lot of repetition of column names in the maps. Basically all the Maps will have the same column names, what is the rationale behind returning so many Maps with similar Keys?

Any insight will be appreciated.

Regards,
Talib




i feel it is the best because Programmer no need to bother on the order so i can get the value by passing the column name and when you iterate you need to concentrate on order of data accordingly you generated the query. more over you can get what ever the column data on without iteration.
can i know what is your prefered approch.


Thanks
Sathish kumar
SCJP, SCWCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inefficiency in queryForList(..) methods of JDBCTemplate