Solved

logic to call back end from java

Posted on 2008-09-30
5
244 Views
Last Modified: 2012-05-07
hi guys

I am trying to figure out a logic for my code scenario.

I have a search screen where user enters range of ids. I have to retrieve information for the range of ids.

for example: 1-100 (i am storing this in string array ids)
i am getting all the id individually and passing each id in my backend query

for(int i=0; i< ids.length ; i++)
{
from jsp--> call middle layer --> call backend and pass 1 to "select * from table where customer_id= 1"
from jsp--> call middle layer --> callbackend and pass 2 to "select * from table where customer_id= 2"
from jsp--> call middle layer --> callbackend and pass 3 to "select * from table where customer_id= 3"
....
....
call backend and pass 100 to "select * from table where customer_id= 100"
 

}

 

but the problem is the above approach is taking long time because in above case i am executing 100 queries
so if the range is 1-10000, 10000 queries are executed which takes a very long time.

Is there any other alternative to this.
One of the options is range search, something like
select * from table where customer_id between 1 and 10000
but i dont want to do that because i need to pass indivual ids in the middle layer and then pass each id
to the back end.

Any idea how i can run the above 100 queries and improve the performance.

thanks v much
J
0
Comment
Question by:jaggernat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 250 total points
ID: 22610330
You could build a List<Integer> or int[] to hold the id values and make one call to the middle tier passing in your List/Array.  

You could then make one call to the backend to find those exact values or use your thought of range searching a return of all the customers with ids 1 --> 10000.  What you could do there is create a bean like Customer to hold each individual record and implement Comparable using the customer_id member as the comparison field.

You can use something like this for range searching lists: http://crossedlogic.blogspot.com/2008/09/range-searching-using-java.html.

Regards,
Kevin
0
 
LVL 23

Assisted Solution

by:Ajay-Singh
Ajay-Singh earned 250 total points
ID: 22611300
In this flow,

from jsp--> call middle layer --> call backend and pass 1 to "select * from table where customer_id= 1"


You can collect the ids, you want to pass, and pass it a array. So, the middle layer, you need
to make modification so as to add api to handle array input. Now, you have a choice to use in query
in the backend with the received ids.
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22611390
Thanks for confirming what I thought, Ajay.  Good to know I was on the right track.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question