It's been recently discussed using the <META REFRESH=...> tag to refresh a page while it's executing; you probably want to spin off a Thread to do the actual query, but you might want to check your servlet engine's documentation before jumping into this head-first. A number of Web servers are starting to do some clustering/scaling behind the scenes, and spinning off a thread can really screw up their algorithms (which is why EJB forbids Beans from starting a Thread).
 
Spinning a Thread off is as simple as creating an anonymous Runnable class to do the work:
 
Connection conn = getTheConnectionFromSomeplace();
Statement stmt = conn.createStatement();
String SQL = "...";
 
Thread workerThread = new Thread(new Runnable()
{
    public void run()
    {
        try
        {
            stmt.executeQuery(SQL); // the usual JDBC thing in here
        }
        catch (Exception x)
        {
            ....
        }
    }
});
workerThread.start();
 
while (workerThread.isAlive())
{
    // Thread is still running, so keep sending back "Please wait" pages....
}
 
Because Runnable.run() doesn't declare any throws clause, you need to catch all Exceptions within run() and handle them in there. Then, when your query completes and stores the result set someplace, workerThread "dies", and the isAlive() test comes back false.
 
You may want to make the anonymous Runnable class a full-fledged public class; anonymous inner classes sometimes have seemingly-strange rules regarding access of members of the enclosing class. It also permits you to reuse the class in a variety of places and situations.
 
HTH.
 
Ted Neward
Patterns/C++/Java/CORBA/EJB/COM-DCOM spoken here
http://www.javageeks.com/~tneward
 "I don't even speak for myself; my wife won't let me." --Me
-----Original Message-----
From: Kenia Nimesh <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Tuesday, June 29, 1999 4:48 AM
Subject: Waiting for a query

Thru servlets I am accessing my oracle database.My query takes a long time to reterive and print the result.
What I  want is till the time the query is executed and displayed . I  want to show the user 
 "Wait for some time , the query is being executed". , and once I get the query executed and result comes at the client side the display message should be  replaced by actual result.
 
How should I do it??
 
Thanks in advance
Nimesh Kenia

Reply via email to