JDBC Three-Tier Model with RMI



Contents
Baseline of Homework

For this assignment, you can choose from

You should not use your JDBC example for this homework unless you make some changes or additions in functionality. Creativity and uniqueness are always appreciated.

Back to Top Page


Resources

Back to Top Page


About the Problem

About the Program

Course Schedule Database is a sample application that demonstrates how JDBC Three-Tier Applet works. It is an example of Distributed Object Programming becuase it uses Java RMI to build up a module (through Stubs and Skeletons) such that client side Applet can call remote methods running on another host machine at Server side.

The program consists of three distinct modules:

First is the Client Applet module --
CourseApplet , which offers an interface for students to query on course information;

The second module is the middle-layer Java RMI, which includes
Course -- RMI Remote Interface (methods declaration available to compiler on both client and server) and CourseImpl -- implementation class of the remote interface.

The third module is the Database Access backend --
myDatabase , which performs database access through JDBC and sends back query results to client applet for display.

Back to Top Page




Client Interface

CourseApplet is the interface which provides a reference for online registration. Students can look up course schedule over Internet. They can browse on machines at client side while the registration system usually runs on another host machine at server side. OPEN, SEARCH, INSERT, CLOSE and GUIDE buttons are provided. The first four operations are actually performed by calling remote methods which run on server side.

OPEN and CLOSE are used for building up connection to JDBC.
SEARCH and INSERT buttons invoke relative pages SearchForm and InsertForm for further query operation.
GUIDE button can be used to switch back to guidline page when users want to refer instructions for the system.
Usage information and query results are given in Status Window.




Back to Top Page


RMI Transport Layer

Course and CourseImpl are classes for RMI Remote Interface and its Implementation respectively. Course is a subclass of the Remote interface in the Java rmi package. It declares remote methods open(), search(), insert(), close(), which can be called by the client like they are local. CourseImpl is the implementation class, which provides methods for each method name specified in the Remote interface. Java compiler produces Stubs and Skeletons classes from the above two classes, which forms a middle, socked-base transport layer for communication between client and server.


Database Backend

myDatabase implements methods to access the Oracle database via JDBC. The API includes open and close connection to database, executeSQL for executing query commands and getRecord for returning multiple records that matches the query. Vector object is used to hold multiple Hashtables as elements, where each record is held by a hashtable. As each query is packaged into a string object that deliverd to execution method. so all of the database access methods in ControlPanel take executeSQL and getRecord as the underline methods. And it is very flexible to expand the functions of query based on this scheme.

I use oracle.jdbc.driver.OracleDriver to connect to the Oracle database on Carver. The database access of my program is actually done all on server side using the above JDBC driver.

Back to Top Page


Diagram




Back to Top Page


Design Notes

The applet uses four main classes for building the client interface. The main applet class is the CourseApplet class which uses BorderLayout scheme to put a TopPage component on top of the page and an MainForm component below it. The TopPage class is extended from Canvas and it just displays the banner on top. The MainPanel component is further consists of LeftPanel and RightPanel. LeftPanel has Open, Search, Insert, Close and Guide button components and actionListioner. But the eventHandler are passed to its parent panel -- MainPanel. RightPanel uses CardLayout to invoke the components (OpenPage, SearchForm, InsertForm , ClosePage and GuidePage) when the related button is pressed. It uses the GridBagLayout and GribBagConstraints classes for placing the components on the screen appropriately for SearchForm and InsertForm. Several components like Textfields, Buttons, Lists and TextArea are placed appropriately on these two Panel. It uses the addComp method in the class to actually place the components and uses the Insets class to give appropriate distances from the borders of the components.

Java RMI adds a number of classes to the Java language for naming Registry, Remote interface, RemoteObjects, RMISecurityManager, RemoteExceptions. Course is the remote interface for both client and server side. CourseImpl is the implementation for the remote interface, which has four methods -- open(), close(), search() and insert(). The first two remote methods are called in MainPanel while the last two remote methods are called in SearchForm and InsertForm respectively. Only search() method return a vector data type to the client, and the other three methods just return boolean type data. All the above four are implemented by calling methods in myDatabsase and perform database access at server side. Query results are returned as vector parameter to client side for display.

In order to run the program, a port number is picked for my name registry ("rmiregistry 1996 &"). The port number has to be put into two files CourseImpl.java and index.html Name.binding and url parameter ("//carver.npac.syr.edu: 1996/CourseServer"). Stub and Skeleton has to be generated ("rmic -d /servers/cgi-http-class/htdoc/cps616spring99-docs/cy99xfq/assgn3/ CourseImpl"). Finally RMI server is started ("java -Djava.rmi.server.codebase=http://carver.npac.syr.edu:3768/cps616spring99-docs/cy99xfq/assgn3/ CourseImpl &").

The myDatabase class implements two important methods executeSQL and getRecord, apart from open and close database methods. All queries are done by calling them througn upper level API doSearch() and doInsert() in SearchPanel and InsertPanel class.

Back to Top Page


Source


Back to Top Page


Demo

The demo applet works with Netscape Communicator versions 4.5, 4.04 with AWT 1.1 patch and 4.05 with AWT 1.1 patch on Solaris machines. To run the demo Click here .


Note

If query to database doesn't work, it might due to the RMI server is down. In order to run the applet, the following steps have to be executed:





Back to Homework Page