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 6026005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:22:56+00:00 2026-05-23T04:22:56+00:00

Currently we retrieve a List of objects from the Spring SimpleJdbcTemplate. The first query

  • 0

Currently we retrieve a List of objects from the Spring SimpleJdbcTemplate. The first query is a select * to retrieve all records that we will want to be our “keys” . This then leads to a foreach loop over the collection which in turn involves N queries back to the database where N is the size of the List. Would it be more efficient to do these N queries or do 2 large select * statements and map them through a for loop that does an if statement? See code below:

N Queries  

List keyList = Select * from keyTable;
for(Object o: keyList)  
   {  
      List valueList = Select * from valueTable;  
      //Map valueTable to keyTable via rowmapper  
    }  




Y Java if statements  
    List keyList = Select * from keyTable;  
    List valueList = Select * from valueTable;  
    for(Object o: keyList)  
       {   
           for(Object z : valueList)  
             {    
                  if(z.key == o.key)  //set the value  
             }   
        } 
  • 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-05-23T04:22:57+00:00Added an answer on May 23, 2026 at 4:22 am

    I’m not a java programmer, but wouldn’t it be simpler to have the database perform the join, since most modern database engines are designed and built to optimize the join process? Guessing at the syntax, you’d have the query

    Select * from keyTable o
     inner join valueTable z
      on o.key = z.key
    

    somehow within your code, perhaps like so:

    List keyValueList = select * from keyTable o inner join valueTable z on o.key = z.key;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently attempting to retrieve a list of objects from my database using jQuery.
I currently have links w/ class=ajax that I want to retrieve the element with
What is the best way to retrieve records from the database? Currently we are
I want to retrieve a date field value from a List and store it
First I retrieve the Note objects in the service layer: List<Note> notes = this.getNotes();
I need to retrieve, in my Win32 standalone program, a list of currently installed
Ok, currently I have a view in my android app that displays a list
First of all, this is the first time that I use Hibernate so my
Is there a simple way to retrieve a filtered list of files from an
I have a few objects that represent a web application. Currently I have a

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.