Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Create an order table and an orderItems table in the books database to storc orders placed by customers. The order table should store an orderID, an orderDate and the email address of the customer who placed the order. [Note: You will need to modify the form in Exercise 11.6 to include the customer's e-mail address]. The order Items table should store the orderID, ISBN, price and quantity of cach book in the order. Modify process.jsp so that it stores the order information in the order and orderttems tables.

Short Answer

Expert verified
Create 'orders' and 'orderItems' tables, add email to the form, and update process.jsp to store order data.

Step by step solution

01

Design the Database Schema

Define the structure for the new tables within the existing 'books' database. Two tables are needed - 'orders' and 'orderItems'. The 'orders' table will contain columns: 'orderID', 'orderDate', and 'email', and the 'orderItems' table will contain: 'orderID', 'ISBN', 'price', and 'quantity'.
02

Create Tables

Write and execute SQL commands to create the 'orders' and 'orderItems' tables: 1. For the 'orders' table: ``` CREATE TABLE orders ( orderID INT PRIMARY KEY AUTO_INCREMENT, orderDate DATE, email VARCHAR(255) ); ``` 2. For the 'orderItems' table: ``` CREATE TABLE orderItems ( orderID INT, ISBN VARCHAR(13), price DECIMAL(10,2), quantity INT, FOREIGN KEY (orderID) REFERENCES orders(orderID) ); ```
03

Modify Form in Exercise 11.6

Add a field to capture the customer's email address in the form used to place orders. Ensure that this field is properly named and connected to the input model that collects order data.
04

Update process.jsp to Insert Order Data

Edit 'process.jsp' to handle inserting the order data into the 'orders' and 'orderItems' tables. This involves capturing order details from the form, executing an SQL insert into the 'orders' table first to create the order, and then inserting each book in the order to the 'orderItems' table: - Insert into 'orders': ```jsp String orderQuery = "INSERT INTO orders (orderDate, email) VALUES (?, ?)"; // Prepare and execute the query using Java's PreparedStatement ``` - Insert items into 'orderItems': ```jsp String itemQuery = "INSERT INTO orderItems (orderID, ISBN, price, quantity) VALUES (?, ?, ?, ?)"; // Loop through books in the order and use PreparedStatement to execute ```

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

Key Concepts

These are the key concepts you need to understand to accurately answer the question.

SQL Commands
SQL commands are the backbone of managing data in a relational database. They are used to perform tasks such as creating tables, inserting data, updating records, and retrieving information. In the context of the solution provided, the SQL commands used were primarily for creating tables in a database, reflecting the design and schema structure that was predefined.

The command `CREATE TABLE` is a crucial instruction for defining new tables. For example, in our exercise, we used this command to establish the 'orders' and 'orderItems' tables. Each table was meticulously defined with specific columns, like `orderID` and `orderDate`, to store necessary information for each order.

SQL commands can also manage data through `INSERT`, `UPDATE`, `DELETE`, and `SELECT` commands. In our solution, the `INSERT` command is vital as it populates data into our freshly created tables. Using placeholders like `?` in the `INSERT` statements helps in executing dynamic queries while enhancing security by preventing SQL injection through Java's `PreparedStatement`.

These SQL commands need to be understood in their syntax and application, as they are essential to achieving efficient data management in databases.
Database Schema
A database schema represents the logical configuration of a database. It consists of tables, columns, data types, and the relationships between the tables. In our exercise, the importance of designing a carefu database schema is clear as it sets the foundation for how data will be stored and accessed.

The schema presented in the exercise includes two tables: 'orders' and 'orderItems'. The 'orders' table holds information about individual customer orders, such as the `orderID`, `orderDate`, and the customer's `email`. Meanwhile, the 'orderItems' table records specific details about each book within an order, including `orderID` (linking it back to the 'orders' table), `ISBN`, `price`, and `quantity`.

Understanding the concept of primary and foreign keys is crucial in schema design. A primary key, like `orderID` in the 'orders' table, uniquely identifies each record and ensures no duplicate entries. The 'orderItems' table references this primary key as a foreign key, establishing a logical link between tables and maintaining data integrity.
  • Primary Key: Uniquely identifies records.
  • Foreign Key: Establishes links between tables.
  • Data Types: Defines the kind of data stored.
Careful planning during schema design helps in efficient query execution, data consistency, and avoids redundancy, making it a cornerstone of database management.
Entity-Relationship Model
The Entity-Relationship (ER) Model is a conceptual blueprint of a database's structure. It serves to visually represent entities, attributes, and relationships between different data elements, aiding in the organization of data requirements.

Entities represent objects or things you are storing information about, such as `orders` and `orderItems` in our exercise. Each entity contains attributes, which hold data values like `orderID`, `orderDate`, `email`, `ISBN`, `price`, and `quantity`. These attributes are the fields that constitute an entity's record.

The ER Model also highlights relationships which are the logical connections between entities. In our case, the relationship between 'orders' and 'orderItems' is exemplified by the `orderID` field. This linkage illustrates how the two tables interconnect, with 'orderItems' relying on 'orders' for associated data.

An ER Model benefits the database design by:
  • Clarifying data requirements and relationships before actual database creation.
  • Providing a diagrammatic representation, making it easier for stakeholders to understand.
  • Assisting in the detection of potential design flaws like redundant data.
Designing with an ER model ensures a well-organized database, facilitating streamlined operations and accurate data retrieval.

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Modify the bookstore case study to cnable the client to change the quantity of an item currently in the shopping cart. In viewCart. jsp, display the quantity in an input element of type text in a form. Provide the user with a submit button with the value Update Cart that enables the user to submit the form to a servlet that updates the quantity of the items in the cart. The servlet should forward the request to viewCart. \(j\) sp, so the user can see the updated cart contents. Redeploy the bookstore application, and test the update capability.

Fill in the blanks in each of the following statements: a) A three-ticr, distributed Web application consists of _______,________and _________ tier. b) The _______ is the default document sent as the response to a client when the client initially interacts with a J2EE application. c) The ______ enables Enterprise Java application components to access information and resources (such as databases) that are external to an application. d) An ________ object provides access to the application’s naming environment. e) A RequestDispatcher object can _____ requests to other resources or _______ other resources as part of the current servlet’s response. f) Sun’s _________ provides XML and XSL capabilities in a Java program. g) Method _____ of interface _______ discards the session object for the current client. h) The _______for an application is the part of the URL that enables the server to deter- mine which application to execute when the server receives a request from a client. i) An Enterprise Java application container must provide a ______ that implements JNDI and enables the components executing in that container to perform name lookups to locate resources. j) The J2EE reference implementation comes with a graphical application, called the ________ that helps you deploy Enterprise Java applications.

State whether each of the following is true or false. If false, explain why. a) The J2EE server uses port 8080 to await client requests. b) When deploying applications with the \(\mathrm{J} 2 \mathrm{EE}\) server, you can launch the Cloudscape and J2EE servers in any order. c) Initialcontext method 1ookup locates a resource with a JNDI name. d) Method lookup returns a connection object representing the connection to the database. e) The Java 2 Enterprise Edition 1.2.1 reference implementation includes the Apache Tomcat JSP and servlet container. P When RequestDispatcher method forward is called, processing of the request by the current servlet is temporarily suspended to wait for a response from the resource to which the request is forwarded. g) Both the ServletRequest and the Servletcontext getRequestDispatchex methods throw exceptions if the argument to getRequest Dispatcher is not a servlet. h) Each resource reference has a corresponding JNDI name that is used by the deployment tool to register the resource with the Java Naming and Directory Service. i) If you do not configure your data sources and other resources before deploying an Enterprise Java application, the \(\mathrm{J} 2 \mathrm{EE}\) server will search the application to determine the resources used and register those resources with the naming server. j) Not including the full package directory structure for a class in a package will prevent the application from loading the class and from executing properly.

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free