We are trying to access a large volume of data from a remote database, but the time it takes to get the data from the database is more than the maximum timeout for the web server, so the webpage is not getting displayed. How can we solve this problem?

Nicholas Whitehead

JDBC is not usually the root cause of the delay, so I'll make the obvious suggestions first:

  • Extend the maximum timeout for the web page.
  • Optimize the query to return the data faster.
  • Reduce the amount of data you return.
  • Increase the bandwidth to the database.
  • Tune the transport protocol to carry more data per packet.
  • Last and most importantly for remote access across a slow line: denormalize the query. One query returning many rows will have a far faster throughput than many queries returning a small number of rows. Differently put, the submission and processing of a query itself can easily longer than the actual retrieval of the rows.

Joe Sam Shirah adds:

jGuru received several answers to this question on the JDBC side, most of which emphasized narrowing the query to take less time. This is excellent advice, but not always possible. Additionally, other tasks may bring up the same issues with servlets. During January, 2000, there was an exchange of messages on Sun's servlet mailing list which discussed the issue and provided a more general answer. Essentially, the advice is to start a new thread in the servlet to do the work and then, using refresh in the header, repeatedly send a status message until the long running task is done.

See the series Timing out of response data. Interestingly, probably the one that outlines the process best is http://archives.java.sun.com/cgi-bin/wa?A2=ind0001&L=servlet-interest&D=0&P=80267 by one Nicholas Whitehead.

Swarraj "sk or raj" Kulkarni and Kesav Kumar Kolla also contributed to this answer.