CSE 4510: Lab Assignment #12

Due: Friday, 23 April 1999

The Task

Extend the previous assignment in which you wrote a Java program to display information from a geneological database. Keep the ability to open the database from a file, but replace the default resource with the data from the real database.

Like the last assignment, this project needs to be encapsulated in a jar file. So that it may be run like this:

java -jar familtytree.jar
Include all source and class files with the jar file. Because of the dependency of the database client program on the underlying JDBC driver in an external jar file, a "download extension" will need to be added to the jar manifest. Make sure it directs access to the jar file:
/export/home/faculty/stansif/idb/RmiJdbc.jar

Database

To see if the data base is working try the following command (on a machine in the Harris Lab):
java -classpath /export/home/faculty/stansif/idb:/export/home/faculty/stansif/idb/RmiJdbc.jar Show
or the more streamlined
java -jar ~ryan/idb/sh.jar
This should show the current contents of the data base. However the database system has a tendency to hang from time to time. If you get no response after a couple of minutes, then the database may be unavailable until I have an opportunity to restart it. You may want your program to use setQueryTimeout.

The java program Show.java connects to the genealogy data base and prints all the data. The basic structure of a connction to this database is as follows:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/* ... */

try {
   Connection connection;
   final String jdbc_url = "jdbc:idb:/export/home/faculty/stansif/idb/sample.prp";
   final String host = "maelstrom.cs.fit.edu";

   Class.forName("RmiJdbc.RJDriver");
   connection = DriverManager.getConnection("jdbc:rmi://" + host + "/" + jdbc_url);
   /* ... */
   connection.close();

} catch (ClassNotFoundException e) {
   System.out.println ("This program must be run with '-classpath=.:/export/home/faculty/stansif/idb/RmiJdbc.jar'");
} catch (SQLException e) {
   e.printStackTrace();
}	
More information can be found at Establishing a Connection in the Java tutorial.

The database consists of one "table" called genealogy and five columns: name, fathers_name, mothers_name, birth_date, and death_date.

The java program Show.java also illustrates result sets. More information can be found at Retrieving Values from Result Sets in the Java tutorial. A more basic query, like an update, is illustrated below:

try {
   final String sql = "UPDATE genealogy SET birth_date = "01/02/03" WHERE name LIKE John";
   Statement upd = connection.createStatement ();
   int row = upd.executeUpdate(sql));  // number of rows updated
   up.close();
}  catch (SQLException e) {
   System.out.println("Update failed");
}

Helpful stuff

Graham Hamilton, Rick Cattell, and Maydene Fisher.
JDBC Database Access with Java: A Tutorial and Annoteated Reference.
Addison-Wesley, Reading, Massachusetts, 1997.
Description: xvi+462 pages, isbn 0-201-30995-5, lccn QA76.73.J38H35 1997, US$37.61.

Turning it in

Submitt all the source files and all the class files in a single jar file. Use the following command:

~ryan/bin/mfiles ryan@cs.fit.edu "cse4510/lab12"  familytree.jar

You may use mfiles to submit the lab assignment as often as you wish up to the due date. Only the last submission matters. All but the last submission will be ignored. You may use mfiles to submit multiple files and directories (if applicable). List all the files and directories on the command line after the subject string. You must submit all the files for an assignment at the same time. With luck the submissions for this lab exercise will be found in the file lab12-sub.txt.


Ryan Stansifer <ryan@cs.fit.edu>
Last modified: Fri Apr 23 16:57:53 EDT 1999