?
Solved

logic to call back end from java

Posted on 2008-09-30
5
Medium Priority
?
248 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 60

Accepted Solution

by:
Kevin Cross earned 1000 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 1000 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 60

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

650 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