Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7735185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:26:16+00:00 2026-06-01T07:26:16+00:00

How to load data from JDBCTemplate.queryForMap() as it returns the Map Interface? How is

  • 0

How to load data from JDBCTemplate.queryForMap() as it returns the Map Interface? How is the query data maintained internally in the map? I tried to load it, but I got this exception: org.springframework.dao.IncorrectResultSizeDataAccessException: Incorrect result

Code:-

public List getUserInfoByAlll() {
    List profilelist=new ArrayList();
    Map m=new HashMap();
    m=this.jdbctemplate.queryForMap("SELECT userid,username  FROM USER");
    Set s=m.keySet();
    Iterator it=s.iterator();
    while(it.hasNext()){
        String its=(String)it.next();
        Object ob=(Object)m.get(its);
        log.info("UserDAOImpl::getUserListSize()"+ob);
    }
    return profilelist;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:26:17+00:00Added an answer on June 1, 2026 at 7:26 am

    queryForMap is appropriate if you want to get a single row. You are selecting without a where clause, so you probably want to queryForList. The error is probably indicative of the fact that queryForMap wants one row, but you query is retrieving many rows.

    Check out the docs. There is a queryForList that takes just sql; the return type is a

    List<Map<String,Object>>.

    So once you have the results, you can do what you are doing. I would do something like

    List results = template.queryForList(sql);
    
    for (Map m : results){
       m.get('userid');
       m.get('username');
    } 
    

    I’ll let you fill in the details, but I would not iterate over keys in this case. I like to explicit about what I am expecting.

    If you have a User object, and you actually want to load User instances, you can use the queryForList that takes sql and a class type

    queryForList(String sql, Class<T> elementType)

    (wow Spring has changed a lot since I left Javaland.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this simple code to load data from other php page using get
I've configured extjs store to load data from useragentstring.com api, this api return data
I am writing a FireFox-Extension and want to load Data from Server. But when
I am trying to load data from SQL to No-SQL i.e Cassandra. but somehow
I have used this code to load data from a plist. -(void)loadOrCreateData { NSLog(@Start
I'm trying to load data from a .txt file with PHP, but I fail
I'm using FlatPack to parse and load data from flat files. This requires loading
I am trying to load data from one table to another. But I only
I'm using a DataGridView to load data from a DataTable. This DataGridView is located
Apache Pig can load data from Hadoop sequence files using the PiggyBank SequenceFileLoader :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.