system architecture: designing the database layer with java, jdbc and sql

20
System Architecture: Designing the Database Layer with Java, JDBC and SQL

Upload: monty

Post on 11-Jan-2016

41 views

Category:

Documents


0 download

DESCRIPTION

System Architecture: Designing the Database Layer with Java, JDBC and SQL. Databases for StressFreev1.3. StudentsDB - id, name, year, advisor, schedule, transcript TranscriptsDB - student, myMajors, myMinor, myCourseRecords, registrar - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: System Architecture: Designing the Database Layer  with Java, JDBC and SQL

System Architecture:Designing the Database Layer

with Java, JDBC and SQL

Page 2: System Architecture: Designing the Database Layer  with Java, JDBC and SQL

© Lethbridge/Laganière 2001

Chapter 9: Architecting and designing software

2

Databases for StressFreev1.3

StudentsDB - id, name, year, advisor, schedule, transcriptTranscriptsDB - student, myMajors, myMinor,

myCourseRecords, registrarCoursesDB - id, title, distrib, sameAs, prerequisites,

myOfferingsOfferingsDB - id, section, labSection, semYear, capacity,

enrollment, myClassList, course, instructor, timeSlot

SchedulesDB - student, approved, finished, numClasses, myClassesInstructorsDB - name, myClasses, myAdviseesTimeSlotsDB - id, days, startTime, endTime

Note: Some of these names are not the same as in your StressFreev1.3.zuml model. We will use the Poseidon-generated Java classes (with these name changes) that are now in the folder StressFreev1.3 at the course web site.

Page 3: System Architecture: Designing the Database Layer  with Java, JDBC and SQL

© Lethbridge/Laganière 2001

Chapter 9: Architecting and designing software

3

SQL - Structured Query Language

A good database software tool (reliable, easy to use, free, and well integrated with Java).

• StressFree database creation, insertion, and queries are easily accomplished with simple SQL commands

• Java/mySQL interface (JDBC and SQL Connector/J) allows us to implement the component of StressFree in Java.

• The database component of StressFree will be part of the server side.

• A good tutorial on SQL (but it’s long!) is at:http://www.bowdoin.edu/~yzhuang/download/John

.Wiley.MySQL.pdf(Look at chapters 3 and 5 for starters.)

• So let’s learn a little about SQL and its Java interface…

Page 4: System Architecture: Designing the Database Layer  with Java, JDBC and SQL

© Lethbridge/Laganière 2001

Chapter 9: Architecting and designing software

4

SQL Overview

A Database is a collection of tables—It can be accessed by the ‘use’ SQL command.—Our database is called ‘csci260’

Each table has rows of values of a certain type—E.g., ‘TimeSlotsDB’ is a table inside the csci260 database with rows of values of type ‘TimeSlot’.

A table is a collection of columns, one for each variable

—It can be created and destroyed by the ‘create table’ and ‘drop table’ SQL commands.

—Information in tables can be accessed, added, changed, removed, or combined with other tables using ‘select’, ‘insert’, and other SQL commands.

Page 5: System Architecture: Designing the Database Layer  with Java, JDBC and SQL

© Lethbridge/Laganière 2001

Chapter 9: Architecting and designing software

5

Getting started: Connecting to the SQL Server— By command line -- our username is ‘csci260’ and our password is ‘regy’.— The host server is a separate machine outside the lab.— Only one database can be accessed at one time.

Page 6: System Architecture: Designing the Database Layer  with Java, JDBC and SQL

© Lethbridge/Laganière 2001

Chapter 9: Architecting and designing software

6

Getting started: Connecting to the SQL Server— In Java we need to import the java.sql.* classes— These provide all the methods for manipulating SQL databases and tables.— This program is in the Eclipse folder ‘workspace260Reg’ at the course web site.

Page 7: System Architecture: Designing the Database Layer  with Java, JDBC and SQL

© Lethbridge/Laganière 2001

Chapter 9: Architecting and designing software

7

Accessing a table in an SQL database— From the command line: use ‘show tables’ and ‘select’ commands

Page 8: System Architecture: Designing the Database Layer  with Java, JDBC and SQL

© Lethbridge/Laganière 2001

Chapter 9: Architecting and designing software

8

Accessing the same table from a Java program – Note that the names are those of the TimeSlot class variables.

Page 9: System Architecture: Designing the Database Layer  with Java, JDBC and SQL

© Lethbridge/Laganière 2001

Chapter 9: Architecting and designing software

9

Creating a new table in an SQL database (Java)

The above lines simulate the SQL commands:mysql> CREATE TABLE myTable (id int, name text);mysql> INSERT INTO myTable (id, name) VALUES (1, ‘Yip’);Mysql> …

Page 10: System Architecture: Designing the Database Layer  with Java, JDBC and SQL

© Lethbridge/Laganière 2001

Chapter 9: Architecting and designing software

10

Accessing and displaying data in a table (Java)

Page 11: System Architecture: Designing the Database Layer  with Java, JDBC and SQL

© Lethbridge/Laganière 2001

Chapter 9: Architecting and designing software

11

Accessing and displaying data in a table (Java)

Page 12: System Architecture: Designing the Database Layer  with Java, JDBC and SQL

© Lethbridge/Laganière 2001

Chapter 9: Architecting and designing software

12

Tables in the Database csci260: CoursesDB

Page 13: System Architecture: Designing the Database Layer  with Java, JDBC and SQL

© Lethbridge/Laganière 2001

Chapter 9: Architecting and designing software

13

Tables in the Database csci260: InstructorsDB

Page 14: System Architecture: Designing the Database Layer  with Java, JDBC and SQL

© Lethbridge/Laganière 2001

Chapter 9: Architecting and designing software

14

Tables in the Database csci260: OfferingsDB

Page 15: System Architecture: Designing the Database Layer  with Java, JDBC and SQL

© Lethbridge/Laganière 2001

Chapter 9: Architecting and designing software

15

Tables in the Database csci260: StudentsDB

Page 16: System Architecture: Designing the Database Layer  with Java, JDBC and SQL

© Lethbridge/Laganière 2001

Chapter 9: Architecting and designing software

16

Tables in the Database csci260: TranscriptsDB

Page 17: System Architecture: Designing the Database Layer  with Java, JDBC and SQL

© Lethbridge/Laganière 2001

Chapter 9: Architecting and designing software

17

1. Package functionally cohesive groupsE.g., Group Student, Transcript,

ScheduleE.g., Client classes vs Server classes

(as in the KnockKnock system)E.g., Database access classes

2. Package functionally related interfacesE.g., StressFree GUI

Relational cohesion =

Low cohesion indicates poor packaging.

System Architecture:Package Design Principles

Number of RelationsNumber of Classes

Page 18: System Architecture: Designing the Database Layer  with Java, JDBC and SQL

© Lethbridge/Laganière 2001

Chapter 9: Architecting and designing software

18

StressFreev1.3 Package Design

Page 19: System Architecture: Designing the Database Layer  with Java, JDBC and SQL

© Lethbridge/Laganière 2001

Chapter 9: Architecting and designing software

19

System Architecture:Deployment Diagrams

Identify software and hardware platforms where the system will run•Each box is a hardware/OS node in the system

•Links between boxes show communication paths and protocols

•Files and other artifacts can appear inside the boxes

•Boxes can be nested

Page 20: System Architecture: Designing the Database Layer  with Java, JDBC and SQL

© Lethbridge/Laganière 2001

Chapter 9: Architecting and designing software

20

StressFreev1.3 System Architecture