Solved

logic to call back end from java

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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…
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.

757 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

18 Experts available now in Live!

Get 1:1 Help Now