[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

Too many tuples from the database and my application crashes.

Hello all,

        When i am retrieving data from the database depending on a criteria issued by user, i am storing the results in request scope and displaying them for the user a list. When this list gets too large my application crashes !! What should i do ?  How can i get around this problem ??

Thank You,
0
letsbedecent
Asked:
letsbedecent
  • 12
  • 12
  • 8
  • +1
1 Solution
 
CEHJCommented:
You could stop reading and close the result set perhaps?
0
 
StillUnAwareCommented:
code snippets would help
0
 
CEHJCommented:
You might also consider some sort of shared cache
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
letsbedecentAuthor Commented:
Can u guys be a bit more detailed... any supporting code or sites can be of great help.
0
 
letsbedecentAuthor Commented:
>>You could stop reading and close the result set perhaps?

Then how will i show all the results...  ??  Suppose his query gets back 1000 rows from the database, then is there no way to show him those ??
0
 
objectsCommented:
You should be closing your resources in your finally block, that way it will get run regardless of what happens

try
{
   // do your db stuff in here
}
catch (Exception ex)
{
   // log any errors and do any error handling required
}
finally
{
   // close all database resources
}
0
 
CEHJCommented:
Well it's you who needs to be more detailed, then we can be more specific ;-)
0
 
objectsCommented:
> Then how will i show all the results...  ??

Depends on the error, if its a db error theres not much you can do
Otherwise you may be able to catch the error (see example above) and handle it, and still display the data to them.
0
 
CEHJCommented:
>>you should be closing your resources in your finally block

Please confirm that you are closing. My comments are made assuming no errors of this kind
0
 
letsbedecentAuthor Commented:
Suppose his query gets back 1000 rows from the database, then is there no way to show him those ??

This is the problem.... isnt that clear ?
0
 
StillUnAwareCommented:
I meant You should post Your code snippets :)
0
 
letsbedecentAuthor Commented:
This is the error its displaying

ServletException in:/errorPage.jsp] null' java.lang.NullPointerException
0
 
StillUnAwareCommented:
What is the reason for crashing? If it's OutOfMemoryError then it's possible to allow for VM to use more RAM.
0
 
letsbedecentAuthor Commented:
But this error is raised only when the query asks for data over the past year or so... if the data is required for only past month, this error is not generated !!
0
 
objectsCommented:
That error is occurring on your error page, theres probably a different error also occurring
check your logs
0
 
letsbedecentAuthor Commented:
ok i will definetely do that.,

But, while posting these question, i got a doubt. Suppose if we go to monster.com and type in "Java" in the keywords section, (probably there are many more users doing the same search), the amount of results we get would be very Huuuuuuuuuuge....and is it a good idea to store them in session scope /  any other scope, because memory is limited right., so what do they do normally to handle these kind of huge simultaneous requests ??
0
 
objectsCommented:
tyou may limit the query to only return 100 rows.
0
 
letsbedecentAuthor Commented:
so, no matter how many types u hit the same database, you cannot see the records from 101 ??
0
 
objectsCommented:
eg.

select top 100 * from table
0
 
letsbedecentAuthor Commented:
>>types

its times
0
 
CEHJCommented:
>>so what do they do normally to handle these kind of huge simultaneous requests ??

Have huge resources for one thing. Without knowing what you're doing and what queries are being made against what, it's not easy to advise about caching etc.
0
 
objectsCommented:
and you also offer them a link to the the next (and previous) rows.
0
 
objectsCommented:
the following may be useful to yuo:

http://jsptags.com/tags/navigation/pager/index.jsp
0
 
letsbedecentAuthor Commented:
so when we hit the next button, we actually hit the database again to get the next 100 rows ?? How can we specify that in a query ?
0
 
letsbedecentAuthor Commented:
CEHJ,

In my case, i have a page where the user can select the dates startDate and endDate. I have to return all those rows which were created between these dates. I have a column of type DateTime which contains the value of the time this particular row was created. So, the query is simple, but if he specifies a date range of more than a year (which is probably returning a little more than 2000 tuples) the above error is displayed. I am checking the logs now actually.
0
 
CEHJCommented:
Well that sounds like a potential candidate for caching. You could cache n 'pages' of results from x to y perhaps and, provided your data are not frequently updated, you could just hit the appropriate 'page' and return the results. Multiple requests could read the same cache
0
 
objectsCommented:
>  How can we specify that in a query ?

use:

select * from mytable LIMIT <offset>, <no records>
0
 
objectsCommented:
> Well that sounds like a potential candidate for caching.

You don't want to be caching as it could be huge.
0
 
letsbedecentAuthor Commented:
>>select * from mytable LIMIT <offset>, <no records>

offset is 101
and
no records is 100

is that correct ??
0
 
objectsCommented:
no, offset is 100
(first row is 0)
0
 
letsbedecentAuthor Commented:
For the first 100 rows:
select * from myTable LIMIT 100, 0

For the next 100
select * from myTable LIMIT 100, 101(this is the first row to be retrieved now)

Is this correct ?
0
 
objectsCommented:
For the first 100 rows:
select * from myTable LIMIT 0, 100
For the next 100
select * from myTable LIMIT 100, 100

0
 
CEHJCommented:
>>You don't want to be caching as it could be huge.

There's no 'could' about it. The point about caching is that you *know* what resources you're using, so if they're within limits then there's no problem.

If you're going to limit the results returned, then you'll need to implement paging. Don't try to do that yourself - there are already libraries that implement this, e.g.

http://jsptags.com/tags/navigation/pager/index.jsp
0
 
objectsCommented:
CEHJ,

Please read previous comments so as to avoid duplicating posts.
0
 
CEHJCommented:
OK - sorry i missed that link
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 12
  • 12
  • 8
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now