Frage

I have a scenario like this :
I have a website that users send range of date for example 2013-01-01 to 2013-01-04 and then I need to get some information from the database for each day in a range for example in the above scenario I have to send request to database 3 times:

2013-01-01 to 2013-01-02,2013-01-02 to 2013-01-03,2013-01-03 to 2013-01-04

so as you can see if I want to extract for a month then this would take so long. A better and faster Idea is to call database once and extract all information , for example this range 2013-01-01 to 2013-01-04, all at once and filter information according to each day in java.

Is there anyway that I can do that in java with the help of result set? I appreciate also if anyone has a better idea to handle this scenario ?

Update :

Here is the query that I am using :

SELECT enID, sum(frequency) from entity-epoch
WHERE dateID IN(
    SELECT dateid
    WHERE startdate>=2013-01-01 AND enddate<=2013-01-02)
GROUP BY sum(frequency)

and I have a loop thatcall it for each day?(instead of thoes dates above that I put for better readability I have ? and feed it with different dates.

War es hilfreich?

Lösung

A better idea still is to only fetch the data you actually want to process, via a suitable WHERE clause.

Andere Tipps

As @EJP suggested, you are most likely better off only pulling the data that you actually need, rather than consuming extra lines and cycles pulling it all then processing it.

This is especially true if you are pulling the data using SELECT *, because future changes to the database schema can have potentially deleterious effects on your program's logic. This actually came up recently on the programmers exchange site.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top