Assignment 3: Web Application using JSF & JDBC

Learning Objectives

  1. Able to program a simple database backed web application in java
  2. Know how to use tutorials and sample code from the internet to do (1)

End Product

The following screencast shows a demo of the web application you will be developing in this assignment:

http://youtu.be/yTKsp_NFMTM

Task A (30 pts)

Follow the tutorial linked below to create a JSF 2.x web application that generates a random integer and asks the user to guess the number. When the user enters his guess, the web application responds with whether the guess is correct or not.

https://netbeans.org/kb/docs/web/jsf20-intro.html

Note that you may need to install a version of Netbeans with J2EE support.

Task B (70 pts)

You are going to modify the application in Task A to store all attempts at the number guessing game into a database table. The web application will display the most recent 20 guesses from the content of the database table in the index.xhtml page. Whenever the user enters a guess for the number, the application should insert the timestamp and the number into the database table. You should use the JSF datatable widget to display the most recent 20 guesses.

The following tutorial shows how to use JDBC to connect your web application to the MySQL DBMS.

http://www.mkyong.com/jsf2/jsf-2-0-jdbc-integration-example/

However, in this assignment, you will be connecting to your Oracle database and not the MySQL database in the above tutorial. The following sample JDBC code shows how you can connect to an oracle database:

http://www2.hawaii.edu/~lipyeow/ics321/core/oracle-jdbc.zip

You should create a table named “Attempts” in the database that stores a timestamp, the user guess, and the correct number.

Alternate Requirements

For those of you who have environments that make connecting to the Oracle DB in the VM difficult, the requirements of the assignment will be relaxed to connecting to the Java DB (Apache Derby) that comes pre-installed with your netbeans IDE. See

https://netbeans.org/kb/docs/ide/java-db.html

to setup the database.

You MUST create and use a database named “ics321”. The userid must be set to “DBUSER” and the password set to “ics321”. Your table must have the following schema:

CREATE TABLE Attempts (atime Timestamp, usernum integer, actualnum integer);

Submission Instruction

Zip up the entire jsfDemo directory and attach it to this Laulima->Assignment.