Solved

logic to call back end from java

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
custom annotations 9 38
factorial example 4 39
login form jsp example 2 25
CSV file parsing thru Java 13 28
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

770 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