Technical Support
Discussion Forum
Online Training
Read About Java
Java In-Depth
Product Discounts
Membership Information JDC Resources DukeDollars

Java Cup Logo

JDC Home Page

JDC Applets
(chat, newsreader, calendar)

Log Out

Online Training
shadowSearchFAQFeedback

Course Notes Table of Contents | Exercises
JDBC Short Course Index | Online Training Index

Applet-Based Guestbook
Working Applet | Help
Solution

Prerequisites

Skeleton Code

Due to the volume of comments received from the students, you want to convert the Command-Line Guestbook to work as an applet. Depending upon the JDBC driver you are using, and the location of the database server, the safest thing to do is to create a third tier to provide seamless access.

The purpose of this exercise is to create the third tier and glue everything together. CommentsApplet serves as the completed frontend, so you don't have to worry about creating the GUI (although you can improve upon it if you want). CommentsClient serves as the applet piece that talks to the backend you are creating, so you don't have to worry about the network communications. The CommentsServer skeleton already contains the code for a multithreaded server. It is your responsibility to come up with the code to deal with each connection, the run method. As with the previous example, there is both a query and update mode.

To test out your server without the GUI/applet, use CommentsClient.
To insert: java CommentsClient name username comments
To query: java CommentsClient

Perform the following tasks:

  1. Copy the odbc.datasource file from the previous exercise.

  2. Each connection to the CommentsServer creates an instance of CommentsConnection. It is your job to fillin the run method for this Thread. First determine which command came across. Valid commands are query and insert.

  3. For insert mode:
    • Read the name, username, and comments from the ObjectInputStream.
    • Setup the Connection to the DriverManager.
    • Create a statement.
    • Populate/execute it.

  4. For query mode:
    • Setup the Connection to the DriverManager.
    • Create a statement.
    • Execute it.
    • Read in ResultSet.

  5. Close each statement.

  6. Close the connection.

If you do not want to create specialized servers, you can buy them or use a JDBC driver that permits direct access from your applet with security ramifications. Sybase's jdbcConnect is one such product and the Imaginary JDBC driver for mSQL is another. One of the first Java middleware's on the market, even before JDBC, was from WebLogic.

The task numbers above are linked to the step-by-step help page. Also available is a complete solution, which meets these requirements, and Expected Behavior.


Copyright © 1997 MageLang Institute. All Rights Reserved
May-97 Copyright © 1996, 1997 Sun Microsystems Inc. All Rights Reserved