Solved

logic to call back end from java

Posted on 2008-09-30
5
241 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
My project did see openJDK that I installed. What could be the problem 7 122
json example 39 132
servlet example issue 6 30
tomcat not starting 6 29
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now