Sanjay Sthapit, Spring 1998
![]()
Part I
Part II
I have assumed that an acceptable Access database has already been set up on the server machine. I have also assumed that the required SQL statements are gotten from some unspecified source.
On the server side, the remote object includes 4 methods - myopen to open a connection to the database, rmiSelect to perform selects, rmiUpdate to perform updates, and myclose to close the database connection. Both rmiUpdate and rmiSelect take as parameters a valid SQL statement in the form of a string. rmiSelect returns its result as a serialized content object serObj, which simply contains the ResultSet from the select statement. The servlet installs a security manager, instantiates the remote object and registers it with the server registry as midterm.
The client applet first gets a reference to the remote object from the server's registry. It then opens a connection to the database using the myopen method of the remote object. The applet passes it a UID and a password for the database that the remote object will use to open a connection. The applet can now perform remote selects and updates on the database using the remote object's rmiSelect and rmiUpdate methods.To each of these methods, the client must pass a proper SQL statement as a string (which the remote object's method will use to perform the desired actions on the database). The rmiSelect method returns its result as a serialized object of the type serObj that simply contains the ResultSet of the select query. The applet can now access the Result Set within the returned serObj and display it's contents as it wishes. After it is done, the applet closes the connection to the database using the remote object's myclose method.
Steps to run the application :-
1. Compile all code. Compiling the servlet requires that the Java Server lib be included in the CLASSPATH. The locations of the generated servlet classes must be visible via the CLASSPATH variable, or in the servlets directory in the root directory of the server.
2. Generate stubs and skeletons of the remote object implementation. This is done by running rmic on the interface implementation class. The stub must be visible to the client, while both the stub and the skeleton must be visible to the servlet.
3. Start an rmi registry using rmiregistry (we need to make sure that the port is the same one specified in our servlet code).
4. Invoke the servlet.
5. Run the client applet.