File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes JSP & JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP & JDBC" Watch "JSP & JDBC" New topic


Harry Singh
Ranch Hand

Joined: May 02, 2001
Posts: 124
Hi Java Gurus,
While reading JSP & JDBC, a doubt just came in my mind.Suppose my query fetches about ten lacks or may be more results from the DB.How will i handle it programatically. if there are so many results in ResultSet object, then will this object be in memory and this is also not a right approach to keep this object in memory.
If i try to get less results from DB, then i will have to do DB operations again and again, which is also not a desirable approach..
so what wil be the best approach in this context..
Thanks in advance..
Preeti Rande

Joined: Jun 26, 2003
Posts: 5
u can cache the result.
Harry Singh
Ranch Hand

Joined: May 02, 2001
Posts: 124
How can i cache the result and even if i cache the result that will mean that the object will be in memory...
Out of these 10 lakhs record or may be more, i wanna display just 100 at a time on page. i can do this by pagenation, but do i need to make DB intensive operations everytime or i can get all the results from DB is one single object.
Thanks in advance
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

There are a number of solutions and most have been covered in this forum, as weel as the Servlets and JDBC forums. I recommend searching these forums for "ResultSet paging" first.
The solution you choose will depend on the frequency of searches, the expected number of results, the size of each item, whether the query is cached or needs to be constantly updated from the DB, what load you are allowed to put on the database, how much network traffic you expect and other issues.
There is no single solution, it depends on how the factors above relate to your particular situation.
You could cache the results on the session, you could cache the results on the application if you expected others to execute the same query, you could store just the IDs on the session and load the data as required, you could execute the entire query every time and pull off the entries you wanted, you could use a disconnected ResultSet, you could use a paged ResultSet (ie only return results 101 to 200) or one of many other solutions.
Have a look at previous discussions we've had.
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
What is a "disconnected ResultSet" ?

Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Harry Singh
Ranch Hand

Joined: May 02, 2001
Posts: 124
Hi David,
Can we know about the disconnected resultSet, never heard of it.
how do we usually cache a ResultSet object. Does that means stroing object in session.
Thanks in advance,
I agree. Here's the link:
subject: JSP & JDBC
It's not a secret anymore!