Servers, Servlets, and Applets
Page 4 of 4

Working with a Database Applet

NOTE: You can do this example if you purchased and installed Cloudconnector.

Overview

The JBMSTours application includes an applet. An applet is a "client-side" Java application that runs embedded in a Web browser. The applet uses the Cloudconnector client driver to connect to Cloudscape running in the Cloudconnector framework. Cloudconnector provides both the HTTP and database services; it is both a Web server and a database server.

NOTE: The applet runs only in Web browsers supporting at least JDK1.1.4.

No instructions are provided for using appletviewer.

About the Applet

The JBMSTours application includes the class JBMSTours.applet.ClientApplet. This applet starts the Cloudconnector client driver, opens a connections to the toursDB database, and provides a SQL query window for the connection with the first suggested query already filled in.

If you wish, examine the source code for the applet, JBMSTours.applets.ClientApplet.java, in /demo/programs/tours/JBMSTours/applets.

The directory /demo/programs/tours/JBMSTours also contains a supporting HTML page, ClientApplet.html.

Configure and Start Cloudconnector

NOTE: These instructions assume that you are familiar with how to start Cloudconnector on the command line. You will need to restart Cloudconnector in this example. For a good introduction to how to start Cloudconnector, see the instructions for running Cloudscape's simple demo. You will need to restart Cloudconnector in this example.

  1. Stop Cloudconnector if it is already running.
  2. Open a command window.
  3. Change directories to your weblogic.system.home directory, the directory in which you keep the CloudscapeServer folder and the weblogic.properties file. The default location for these is %CLOUDSCAPE_INSTALL%/frameworks/cloudconnect.
  4. In this window, set the class path to include:
  5. Use a Cloudscape utility that tests your class path for a particular environment. You will run it once with the arguments CloudconnectorServer, to test for a Cloudconnector server environment, and sampleApp, to test for the sample application libraries. You will run it again with the argument CloudconnectorClient, to test for a Cloudconnector client environment (the server serves up client classes to the applet remotely).

    java COM.cloudscape.tools.sysinfo -cp CloudconnectorServer sampleApp

    java COM.cloudscape.tools.sysinfo -cp CloudconnectorClient

    The utility displays a message indicating success or failure. If you got a failure message, check your class path carefully.

  6. Edit the weblogic.properties file as follows:

    Register WebLogic's ClasspathServlet so that you can load HTML pages and other resources from the class path.

    Give it the virtual name CloudscapeExamples. To do that, search in the file for weblogic.servlet.ClasspathServlet. Copy the line and paste it below the current line. In the new text change classes to read CloudscapeExamples. It should read:

    weblogic.httpd.register.CloudscapeExamples=\
        weblogic.servlet.ClasspathServlet

  7. If you already did the servlets lesson, comment out the lines that registered the two servlets, OpeningServlet and GetHotelsForCity.
  8. Save the file.

    For this example, do not run Cloudconnector in JDK1.2. Use any 1.1 JDK except JDK1.1.7. The applet does not work if Cloudconnector is running in JDK 1.2.

  9. Start Cloudconnector on the command line from this directory, like so:

    java -ms16m -mx32m -Dcloudscape.system.home= your_tutorial_system COM.cloudscape.core.CloudscapeServer

Access the Applet from a Browser

The applet used in this demo is a JDK1.1 applet. It requires support and fixes made in JDK1.1.4 to operate in a Web browser. You can use either of the following browsers:

The browsers do not need any classes in their class path for this demo. The applet will download all needed classes from the Web server.

NOTE: If you are using Netscape Navigator, your system CLASSPATH mustnot contain any of the classes the applet will download from the server. It is safest to clean out the system class path before starting the browser.

  1. Start a browser on the same machine as the server, or any machine on the network.
  2. Open the following location:

    http://<serverName>:<portNumber>/CloudscapeExamples/JBMSTours/applets/ClientApplet.html

    replacing <serverName> and <portNumber> with the correct server name and port number. Most likely, these will be localhost and 7001.

    Once the HTML page is downloaded, it loads the applet that provides a window that allows you to send an SQL-J statement to Cloudscape. The results will appear in the new window. The page comes preloaded with a query of the Cities table.

  3. Click the Execute Statement button to execute the statement.
  4. You can execute any of the queries you've learned throughout this tutorial.

NOTE: The applet only supports one statement per execution; do not send batches.

Security restrictions require that the applet access a database server on the same machine as the Web server that served it up. In this example, Cloudconnector is both the Web server and the database server, so access is not a problem. If you want to test the applet from behind a firewall, you will need to set up Cloudconnector for HTTP tunneling.