Chapter 15 - Creating More Complex Database Applications 1 Chapter 15 Creating More Complex Database Applications.

Slides:



Advertisements
Similar presentations
Tutorial 3 Queries and Table Relationships
Advertisements

Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
Exploring Microsoft Access 2003 Chapter 6 Many-to-Many Relationships: A More Complex System.
ISP 121 Access Normalization and Relationships. Normalization Say we’re operating a pet day-care and we need to keep information on our pets/customers.
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making.
Chapter Physical Database Design Methodology Software & Hardware Mapping Logical Design to DBMS Physical Implementation Security Implementation Monitoring.
Object-Oriented Application Development Using VB.NET 1 Chapter 13 Introduction to Data Access Classes and Persistence.
Object-Oriented Application Development Using VB.NET 1 Creating a String Array Code to create a String array: ' declare a String array with 4 elements.
Object-Oriented Application Development Using VB.NET 1 Chapter 7 Adding Responsibilities to Problem Domain Classes.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Introduction to Structured Query Language (SQL)
Chapter 14: Advanced Topics: DBMS, SQL, and ASP.NET
1 Chapter 2 Reviewing Tables and Queries. 2 Chapter Objectives Identify the steps required to develop an Access application Specify the characteristics.
Object-Oriented Application Development Using VB.NET 1 Chapter 9 Implementing Association Relationships.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
CS708 Fall 2004 Professor Douglas Moody –MW – 2:15-3:55 pm –Friday – 6:00-9:20 pm – – –Web Site: websupport1.citytech.cuny.edu.
Database Constraints. Database constraints are restrictions on the contents of the database or on database operations Database constraints provide a way.
Define Table Relationships—1 of 3 One of the most powerful features of a relational database management system, such as Access, is its ability to define.
Chapter 9 - Implementing Association Relationships1 Chapter 9 Implementing Association Relationships.
1 Microsoft Access 2002 Tutorial 3 – Querying a Database.
Introduction –All information systems create, read, update and delete data. This data is stored in files and databases. Files are collections of similar.
ASP.NET Programming with C# and SQL Server First Edition
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
Database Management System Lecture 6 The Relational Database Model – Keys, Integrity Rules.
DAY 15: ACCESS CHAPTER 2 Larry Reaves October 7,
DAY 14: ACCESS CHAPTER 1 Tazin Afrin October 03,
Microsoft Access 2003 Define some key Access terminology: Field – A single characteristic or attribute of a person, place, object, event, or idea. Record.
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
IE 423 – Design of Decision Support Systems Database development – Relationships and Queries.
Implementing an REA Model in a Relational Database
Object Persistence Design Chapter 13. Key Definitions Object persistence involves the selection of a storage format and optimization for performance.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
1 Outline  What is a Primary Key?  AutoNumber primary keys  Single-field primary keys  Composite-field primary key  About Foreign Keys  Database.
M1G Introduction to Database Development 2. Creating a Database.
Chapter 14 - Designing Data Access Classes1 Chapter 14 Designing Data Access Classes.
Relational Database. Database Management System (DBMS)
Chapter 12 - Designing Multiwindow Applications1 Chapter 12 Designing Multiwindow Applications 12.
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making Chapter.
Object-Oriented Application Development Using VB.NET 1 Chapter 6 Writing a Problem Domain Class Definition.
Chapter 8 - Additional Inheritance Concepts and Techniques1 Chapter 8 Additional Inheritance Concepts and Techniques.
Copyright 2007, Paradigm Publishing Inc. ACCESS 2007 Chapter 2 BACKNEXTEND 2-1 LINKS TO OBJECTIVES Creating Related Tables Creating Related Tables Determining.
Exploring Microsoft Access Chapter 6 Many-to-Many Relationships: A More Complex System.
INFORMATION TECHNOLOGY DATABASE MANAGEMENT. Adding a new field 1Right click the table name and select design view 2Type the field information at the end.
Data Driven Designs 99% of enterprise applications operate on database data or at least interface databases. Most common DBMS are Microsoft SQL Server,
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Commercial RDBMSs Access and Oracle. Access DBMS Architchecture  Can be used as a standalone system on a single PC: -JET Engine -Microsoft Data Engine.
06 | Modifying Data in SQL Server Brian Alderman | MCT, CEO / Founder of MicroTechPoint Tobias Ternstrom | Microsoft SQL Server Program Manager.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 16 Using Relational Databases.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
Access Chapter 1: Intro to Access Objectives Navigate among objects in Access database Difference between working in storage and memory Good database file.
1 CHƯƠNG 4 Creating Relational Databases Understanding Table Relationships Example: This database tracks customers and their orders in two separate.
Session 1 Module 1: Introduction to Data Integrity
Object-Oriented Application Development Using VB.NET 1 Chapter 9 Implementing Association Relationships.
MSOffice Access Microsoft® Office 2010: Illustrated Introductory 1 Part 1 ® Database & Table.
Manipulating Data Lesson 3. Objectives Queries The SELECT query to retrieve or extract data from one table, how to retrieve or extract data by using.
Object-Oriented Application Development Using VB.NET 1 Chapter 11 Using Multiple Forms with Problem Domain Classes.
Object-Oriented Application Development Using VB.NET 1 Chapter 13 Introduction to Data Access Classes and Persistence.
CSC314 DAY 8 Introduction to SQL 1. Chapter 6 © 2013 Pearson Education, Inc. Publishing as Prentice Hall SQL OVERVIEW  Structured Query Language  The.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
Object-Oriented Application Development Using VB.NET 1 Chapter 15 Assembling a Three-Tier Windows Application.
Lec-7. The IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax SELECT column_name(s) FROM table_name WHERE.
XP Chapter 1 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Level 2 Objectives: Understanding and Creating Table.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
© 2016, Mike Murach & Associates, Inc.
IS444: Modern tools for applications development
IS444: Modern tools for applications development
Creating More Complex Database Applications
Appendix D: Network Model
Presentation transcript:

Chapter 15 - Creating More Complex Database Applications 1 Chapter 15 Creating More Complex Database Applications

Chapter 15 - Creating More Complex Database Applications 2 One to One Relationships  There is a one-to-one relationship between Customer and Boat  A customer always owns exactly one boat and a boat always belongs to just one customer  Use a database to implement the one-to- one association using a relational database 15

Chapter 15 - Creating More Complex Database Applications 3 Understanding Tables in CustomerAndBoatDatabase 1.Create Chapter15Example1 folder 2.Locate CustomerAndBoatDatabase.mdb on the CD 3.Open CustomerAndBoatDatabase using Microsoft Access 4.View the contents of the BoatTable  The primary key of BoatTable is StateRegistrationNo 5.View the contents of the CustomerTable  The primary key of CustomerTable is PhoneNo 15

Chapter 15 - Creating More Complex Database Applications 4 Understanding Tables in CustomerAndBoatDatabase 15

Chapter 15 - Creating More Complex Database Applications 5 Understanding Tables in CustomerAndBoatDatabase 15

Chapter 15 - Creating More Complex Database Applications 6 Understanding Tables in CustomerAndBoatDatabase 15

Chapter 15 - Creating More Complex Database Applications 7 Understanding Tables in CustomerAndBoatDatabase

Chapter 15 - Creating More Complex Database Applications 8 Understanding Tables in CustomerAndBoatDatabase 15

Chapter 15 - Creating More Complex Database Applications 9 Using SQL to Join Table in Database  The SQL statement to find and display the state registration number and manufacturer of all boats in BoatTable together with the name and phone number of each boats owner: SELECT StateRegistration, Manufacturer, CustomerName, PhoneNo FROM BoatTable, CustomerTable WHERE CustomerPhoneNo = PhoneNo; 15

Chapter 15 - Creating More Complex Database Applications 10 Using SQL to Join Table in Database  The SQL statement displays the state registration number, name, and address of the owner of the boat with state registration number MO98765: SELECT StateRegistration, Manufacturer, CustomerName, PhoneNo FROM BoatTable, CustomerTable WHERE CustomerPhoneNo = PhoneNo AND StateRegistrationNo = ‘MO98765 ’; 15

Chapter 15 - Creating More Complex Database Applications 11 Establishing a Common Connection  Need a new class named CustomerAndBoatDatabaseConnect  It is responsibility of this class is to manage the connection to the database  The initialize method establishes a connection of the database

Chapter 15 - Creating More Complex Database Applications 12 Modifying the Customer PD  Include a boat reference attribute  Initialize boat reference to null in constructor  Include setter and getter methods to set and retrieve boat reference  Use the common database connection established by CustomerAndBoatDatabaseConnect

Chapter 15 - Creating More Complex Database Applications 13 The BoatDA Class  Adds find, add, delete, and update methods  Defines a boat reference variable and a Vector of boat reference variables 15

Chapter 15 - Creating More Complex Database Applications 14 The BoatDA Class – Initialize and Terminate  Initialize uses the database connection established by CustomerAndBoatDatabaseConnect to create a Statement  Terminate closes the Statement instance 15

Chapter 15 - Creating More Complex Database Applications 15 The BoatDA Class – find and getAll Methods  The find method defines a SELECT statement that retrieves a particular record from BoatTable  Find throws a NotFoundException if the record is not found  The getAll method returns a Vector of boat references 15

Chapter 15 - Creating More Complex Database Applications 16 The BoatDA Class – addNew Method  Similar to the addNew method of the Customer class  Extracts boat attributes from the boat instance received  Create a SQL INSERT statement  Before executing INSERT need to confirm that the database does not already contain a duplicate – using the find method  If a duplicate is found a DuplicateException is thrown

Chapter 15 - Creating More Complex Database Applications 17 The BoatDA Class – update and delete Methods  The update and delete methods extract attributes from the boat instance received in the argument list, then define the appropriate SQL statements  Before executing UPDATE and DELETE need to confirm that the database already contains the record – using the find method  If a record is not found a NotFoundException is thrown

Chapter 15 - Creating More Complex Database Applications 18 Modifying the Boat Class to Work with BoatDA  Can extend the functionality of the Boat PD to use the BoatDA class  The Boat class needs four static methods:  Initialize  Find  getAll  Terminate  Three instance methods:  addNew  Update  delete 15

Chapter 15 - Creating More Complex Database Applications 19 Modifying the CustomerDA Class  Change the CustomerDA class to support joining information from the BoatTable and CustomerTable  Now includes a reference to a Boat object 15

Chapter 15 - Creating More Complex Database Applications 20 CustomerDA Class – find and getAll Methods  Change the SQL statement WHERE clause to specify both the join condition and the primary key for the customer of interest

Chapter 15 - Creating More Complex Database Applications 21 CustomerDA Class – find and getAll Methods

Chapter 15 - Creating More Complex Database Applications 22 CustomerDA Class – addNew Method  The is a mandatory one-to-one relationship between Customer and Boat  Must be a customer record for every boat record – the addNew method must enforce this requirement  After inserting a customer record into CustomerTable, a record must be inserted into the BoatTable  Preserves the integrity of the database

Chapter 15 - Creating More Complex Database Applications 23 CustomerDA Class – delete and update Methods  The delete method must also preserve the integrity of the database  When a customer record is deleted, the corresponding boat record must be deleted as well  The update method is unchanged 15

Chapter 15 - Creating More Complex Database Applications 24 Testing the CustomerAndBoatDatabase Application 1.Declare necessary reference variables 2.Invoke the initialization method 3.Attempt to retrieve customer and boat information for customer whose phone number is Use the printDetails method to display the results 5.Try to retrieve a record that doesn’t exist 6.Call the getAll method 7.Create a new Customer and Boat instance 8.Call the addNew method 9.Verify records have been added 10.Test the delete method 11.Test the update method 12.Call the terminate method 15

Chapter 15 - Creating More Complex Database Applications 25 Implementing a One-To-Many Relationship  The relationship between Dock and Slip is a one-to-many relationship  A dock contains many slips  A slip belongs to one dock 15

Chapter 15 - Creating More Complex Database Applications 26 Understanding the Tables in DockAndSlipDatabase 1.Create a Chapter15Example2 folder 2.Copy the DockAndSlipDatabase from the CD 3.Open the database in Microsoft Access 4.View the DockTable  DockID is the primary key 5.View the SlipTable  SlipNo and DockID form the concatenated primary key  DockID is a foreign key for DockTable

Chapter 15 - Creating More Complex Database Applications 27 Understanding the Tables in DockAndSlipDatabase

Chapter 15 - Creating More Complex Database Applications 28 Understanding the Tables in DockAndSlipDatabase

Chapter 15 - Creating More Complex Database Applications 29 Common Connection to DockAndSlipDatabase  Need a separate DA class to establish a connection  Same as CustomerAndBoatDatabaseConnect class except:  Different data source is used 15

Chapter 15 - Creating More Complex Database Applications 30 Modifying the Dock and Slip Classes  Dock class must be modified to support object persistence in a relational database  Implement the initialize, terminate, find, and getAll methods  Implement a tellAboutSelf method  Don’t need to modify the Slip class nor create a SlipDA class -- WHY?  See Figure on pp

Chapter 15 - Creating More Complex Database Applications 31 Introducing the DockDA Class  Similar to other DA classes, except it does not require insert, update, or delete methods  Methods used to terminate and initialize are similar to other DA classes  See pp

Chapter 15 - Creating More Complex Database Applications 32 DockDA Class – find Method  Needs SQL statement to extract dock and slip information from the database  WHERE clause specifies both the join condition and the primary key for the dock of interest  ORDER BY clause specifies the information returned by the query is sorted by slip number

Chapter 15 - Creating More Complex Database Applications 33 DockDA Class – find Method 15

Chapter 15 - Creating More Complex Database Applications 34 DockDA Class – getAll Method  Similar to find method  Returns dock and slip information for all slips in the marina, sorted by dock and then slip  Dock information is repeated for each slip  Creates only one dock instance however  Control-break logic is used to manage this  See Figure on pp. 563

Chapter 15 - Creating More Complex Database Applications 35 DockDA Class – getAll Method 15

Chapter 15 - Creating More Complex Database Applications 36 Testing the DockAndSlipDatabase Application 1.Define necessary variable and establish the connection to the database 2.Attempt to find Dock 1 3.printDetails method displays information about the dock and slips 4.Attempt to find Dock 2 and slips 5.Invoke the getAll method

Chapter 15 - Creating More Complex Database Applications 37 Testing the DockAndSlipDatabase Application

Chapter 15 - Creating More Complex Database Applications 38 Implementing an Association Class  The Lease class has associated AnnualLease and DailyLease subclasses  Implement the Lease association class in a relational database application

Chapter 15 - Creating More Complex Database Applications 39 Understanding Tables in CustomerLeaseSlipDatabase  Create a Chapter15Example3 folder  Open the CustomerLeaseSlipDatabase  View the CustomerTable, LeaseTable, and SlipTable  Customer phone number is primary key for LeaseTable  Slip number and dock ID are foreign keys in LeaseTable 15

Chapter 15 - Creating More Complex Database Applications 40 Understanding Tables in CustomerLeaseSlipDatabase

Chapter 15 - Creating More Complex Database Applications 41 Understanding Tables in CustomerLeaseSlipDatabase 15

Chapter 15 - Creating More Complex Database Applications 42 Modifying the Customer Class  Need to associate a customer instance with a lease instance  Need to add a lease reference to the CustomerPD class  Include getter and setter methods for the lease reference  See Figure on pp

Chapter 15 - Creating More Complex Database Applications 43 Modifying the Lease and AnnualLease Class  Must associate the lease with a customer’s slip  Need to add a slip reference and customer reference  Include getter and setter references to manage these references  See Figures and

Chapter 15 - Creating More Complex Database Applications 44 Modifying the Slip Class  Must associate a slip with its corresponding lease and customer  Need to add an annual lease reference to the attribute list and set its value to null  Three DA methods are needed:  Initialize  Terminate  Find – requires two parameters – slip number and dock ID 15

Chapter 15 - Creating More Complex Database Applications 45 The SlipDA Class  You must find a particular slip so it can be leased to a customer  Need a SlipDA class  Initialize and Terminate methods are identical to other DA classes  Find method defines a SELECT statement that returns information from the SlipTable for a particular slip 15

Chapter 15 - Creating More Complex Database Applications 46 The AnnualLeaseDA Class  Must find and insert information about annual leases in the database  Define variables for annual lease attributes  Uses standard initialize and terminate methods

Chapter 15 - Creating More Complex Database Applications 47 AnnualLeaseDA Class - find  Query retrieves information from three tables: CustomerTable, LeaseTable, and SlipTable  The WHERE clauses uses the relationships between these tables to create the join conditions  The setCustomer method establishes a link with the annual lease instance

Chapter 15 - Creating More Complex Database Applications 48 AnnualLeaseDA Class - addNew  Receives a reference to the annual lease instance that will be added  Lease amount, balance, payment, and start date are extracted  Before executing SQL statement that inserts into LeaseTable – checks to see if primary key already exists in the database

Chapter 15 - Creating More Complex Database Applications 49 Testing CustomerLeaseSlipDatabase Application 1.Declare instances of AnnualLease, Customer, and Slip 2.Add a new record to LeaseTable 3.Locate customer Find Slip 1 on Dock 1 5.Create a new annual lease instance 6.Retrieve newly added information 7.Close the database connection

Chapter 15 - Creating More Complex Database Applications 50 Testing CustomerLeaseSlipDatabase Application 15