The applet below uses JDBC to retrieve entries from an SQL database and then displays them in a simple GUI element. The database connection is kept open during the lifetime of the applet (init/destroy) whereas the SQL query is repeated for every start/stop cycle.
Enable the display of the Java Console window in your web browser and then watch the messages resulting from actions like visiting or leaving this web page, (de)iconifying the browser, loading another instance of the page in this or an additional browser window, (un)hiding the applet with another window, or dropping this web page from the back/forward/go menu by going back to the referrer page and clicking on a different hyperlink there.
Also notice the different behaviour of different web browsers!
Oh, and by the way, did you notice the bug in the applet that causes the result list in the scrollable list box to grow longer and longer, each time you stop/start the applet (for example, by re-entering the web page with your browser's back and forward buttons)? Makes a nice trick to show that the SQL queries are indeed re-run every time ;-) See applet source code for a hint how to fix this BUG.
Lars Appel, October 1999