Enhancing the Trivia Quiz II — 25 points

For this assignment, you will make the following final modifications to the Trivia Quiz JSF web application:

In preparation for working with databases in JSF applications you should also work through the lab exercise, which involves setting up a database for a Cars JSF application. This exercise counts for 5 of the 25 points. It should be done in Lab on September 30.

The modified application must use a database. The user interface and interactions should be unchanged with two exceptions:

For database setup you should use the procedures described in the "Database Setup" section of Cars: A JSF Application with a Database. This example also provides a model for using JDBC and dealing with database errors.

You can design the database tables according to your level of familiarity with databases. If you have little or no experience with databases you can get by with a single user table that has columns for user name, user password, and number of tries and correct answers for each category. This makes SQL statements easier, but you will either have messier Java code or you will need more SQL statements.

If you have more experience with databases you could go with a 3 table design: a user table (id, name, password), a category table (id, name), and a score table (id, user, category, try count, correct answer count). In the score table, the user and category columns are foreign references using the id columns of the other two tables.

In the 3 table design, the user and category tables are entity tables. The score table is a relationship table, similar to the ownership table in the Cars example. In real world applications this kind of design makes application maintenance easier. For example, you could add new categories of trivia questions without modifying the Java or JSF page code.

Except for dealing with database errors, you should be able to confine the modifications to the application scoped database bean. Its methods need to be modified to access the Derby database rather than local variable tables.

Since the database access uses JDBC, all accesses can throw exceptions. You should modify the method interfaces of the database bean to throw these exceptions. Clients of the database bean need to be modified to handle the exceptions by bringing up an error page that displays the exception message. You should use Cars example as a model for doing this.

In a fully debugged application the user should never see the error page except when a database access fails due to a loss of the connection to the database. You will find, though, that the error page is useful during development. With the error page you won't have to dig through a stack trace to find out what went wrong.

When you have completed the assignment submit it as directed by your TA.