A Sample JDBC Project


Development Requirements
When start developing the exercise, follow the requirements below:
The lists of food items and combos can NOT be saved in or loaded into Java data structures like arrays, ArrayList, LinkedList, HashMap, LinkedHashMap, HashSet, LinkedHashSet, TreeMap, TreeSet, PriorityQueue, Set, Vector, etc. though temporary results or data are allowed to be stored in Java data structures. This requirement will be carefully examined when grading.


Due Date and Submission Methods
Due on or before Wednesday, December 09, 2020 in class:

Objectives
There are more than 200 Java packages available and each one is huge. This course is not even able to cover few of them. This exercise tries to pick a useful one and has students be familiar with how packages work, so when students start working for the industry, they will have an idea of how to pick a Java package and use it to facilitate their works. Almost all business applications require to use databases, so it is very reasonable that the instructor picks the Java Database Connectivity (JDBC) for a detailed study. The JDBC APIs provide data access and management for databases from the Java programming language. This exercise is made as simple as possible. The most difficult part may be to be familiar with the APIs and set up the environment. Once one SQL command in a JDBC program works, the rest would be similar and routine. In addition, the only effective way to learn a programming language is practicing, instead of studying concepts or writing some testing programs.
No pain, no gain 😂


Requirements
This application tries to implement a simple electronic-commerce system using a database. The application includes the following requirements:

Database Design and Implementation
Based on the previous descriptions, database design is supplied by the instructor as follows. The following three tables show sample values of a relational fast-food restaurant database, of which iid, no, and (no, iid) are the primary keys of the tables items, combos, and combo_item, respectively. The no and iid are the foreign keys of the table combo_item.


Database implementation on the instructor machine is shown as follows. The input data is for test only. The users are not supposed to know the IDs.

An Example of Oracle 12c Database Implementation
undcemcs02> sqlplus C##userid/password@//65.52.222.73:1521/cdb1 

SQL*Plus: Release 12.1.0.2.0 Production on Fri Nov 22 17:37:07 2018
Copyright (c) 1982, 2014, Oracle.  All rights reserved.
Last Successful login time: Fri Oct 23 2020 14:55:00 -05:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0
 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real
 Application Testing options

SQL> DROP SEQUENCE  item_seq; 

Sequence dropped.

SQL> CREATE SEQUENCE  item_seq  START WITH 1 INCREMENT BY 1 CACHE 100; 

Sequence created.

SQL> DROP TABLE  items; 

Table dropped.

SQL> CREATE TABLE  items ( 
  2    iid    INTEGER PRIMARY KEY, 
  3    name   VARCHAR(32) NOT NULL, 
  4    price  NUMBER(5,2) NOT NULL ); 

Table created.

SQL> DROP SEQUENCE  combo_seq; 

Sequence dropped.

SQL> CREATE SEQUENCE  combo_seq  START WITH 1 INCREMENT BY 1 CACHE 100; 

Sequence created.

SQL> DROP TABLE  combos; 

Table dropped.

SQL> CREATE TABLE  combos ( 
  2    no     INTEGER PRIMARY KEY, 
  3    price  NUMBER(5,2) NOT NULL ); 

Table created.

SQL> DROP TABLE  combo_item; 

Table dropped.

SQL> CREATE TABLE  combo_item ( 
  2    no   INTEGER NOT NULL, 
  3    iid  INTEGER NOT NULL, 
  4    PRIMARY KEY( no, iid ), 
  5    FOREIGN KEY( no ) REFERENCES combos( no ) ON DELETE CASCADE, 
  6    FOREIGN KEY( iid ) REFERENCES items( iid ) ON DELETE CASCADE ); 

Table created.

SQL> INSERT INTO  items 
  2    SELECT  item_seq.NEXTVAL, 'diet coke', 0.99  FROM DUAL; 

1 row created.

SQL> INSERT INTO  items 
  2    SELECT  item_seq.NEXTVAL, 'double cheeseburger', 2.00  FROM DUAL; 

1 row created.

SQL> INSERT INTO  combos 
  2    SELECT  combo_seq.NEXTVAL, 1.99  FROM DUAL; 

1 row created.

SQL> INSERT INTO  combo_item  VALUES( 1, 1 ); 

1 row created.

SQL> INSERT INTO  combo_item  VALUES( 1, 2 ); 

1 row created.

SQL> SELECT * FROM  items; 

IID            NAME            PRICE
---    -------------------     -----
  1    diet coke                0.99
  2    double cheeseburger      2.00

SQL> SELECT * FROM  combos; 

 NO    PRICE
---    -----
  1     1.99

SQL> SELECT * FROM  combo_item; 

 NO    IID
---    ---
 1      1
 1      2

SQL> commit; 
SQL> exit; 
Disconnected from Oracle Database 12c Enterprise Edition Release
 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application
 Testing options

undcemcs02>

The italic text with a white color and a navy background color is entered by users.



Programming Hints
The following SQL commands and algorithms are for your reference. They may or may not be used in this exercise. Assume the 5 food items and 5 combos are as follows:
A User Interface
An example of the exercise’s interface is shown below:


Evaluations
The following features will be considered when grading: