Download cse4701MySQL

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
MySQL & Project Technology Overview
CSE
255






Project Architecture (3-Tier)
MySQL Administration and Tools
Apache-Tomcat Overview
Introduction to JavaServer Pages
Project Suggestions, Environment Setup
Questions…

[email protected]
Derek Doran CSE255 Project Fall07
Chapter 10-1
n-Tier Architecture
CSE
255



A Type of Abstraction for Developing large-scale
Applications
Define A Tier For Each Component Of A Project That
Can Be Developed In Tandem
 Enables Rapid Application Development
 Focuses The Roles of Each Team Member
Example: 2-Tier Client/Server Architecture
 Application (Client) Tier:
Engineer

Implements Desktop Application
Database (Server) Tier:
DBA Defines
the Schema, Implements Database, Writes
Stored Procedures, etc.
Chapter 10-2
3-Tier Architecture

CSE
255
Project Architecture Requirement: A 3-Tier Web System
 Data Access Tier
 DB

on a Secure Server
Logic (Business Logic), Application Tier
 Servlets, Web Services -

System Processing Code
Presentation Tier
 HTML,
JSP, ASP, ASPX Pages Served on Web Server
http://www.patriotbrothers.com/images/3tier_2.png
Chapter 10-3
Project
CSE
255


You Will Implement And Host All 3-Tiers on One PC!
 MySQL Database Server (Data Tier)
 JSP Backend Code, Servlets, …Code That Handles
Processing (Application Tier)
 Dynamic HTML Pages via JSP/PHP (Presentation
Tier)
Group Members Need To Fill Specific Roles
 Database Administrator
 Graphic Artist and Web Developer
 Software Engineer
 Requirements Analyst (All Team Members)
Chapter 10-4
Database Tier
CSE
255




Secure Storage of Databases
Provide Authenticated Communication Only With
Application Tier
Objective: Keep Databases As Far Away From User
Interface As Possible
 Hide DB Server Address
 Hide Login Information
 Make Database Transparent To User
Let DBA, Req. Analyst Develop DB and Schema
Separate From the Application
Chapter 10-5
Application Tier

CSE
255


A Collection of Shared Procedures and Applications
 Objective: Maximize Reusability
Examples
 Common Processing Over Many Applications
 Single Point of Communication with DB
Keep Processing Logic Separate From Form (GUI)
 Prevents Mixing Of Form Logic….
When

and How to Display Information
With Processing Logic
Cart
Checkout
CC Verification
…etc.
Chapter 10-6
Presentation Tier
CSE
255


Contains HTML, JSP, ASP, PHP pages for Presentation
Enables Graphic Designer, Web Developer to Develop
Attractive Pages independently Of Business-Level
Processing
 Graphic Designer
Make The
Static HTML Pages
Develop Page Resources (Images, Flash, Video, etc.)
Write Client-side Scripts (JavaScript/PHP) For Page

Web Developer

Modify HTML For JSP, ASP…
 Communicate With Application Tier Developer
Chapter 10-7
Project Flexibility
CSE
255




All Technologies At All Tiers Can Be Substituted For
What You Are Most Familiar With
 Implementation in JSP, PHP, ASP, .NET...
BUT
 Your Pages Must Run On a Free, Widely
Supported Application Server
 Ex: If ASP.NET, VS 2005 or Web Express
If you Deviate From JSP and Apache Tomcat…
 Alert Prof. Demurjian and I By E-Mail
 Direct Us To Free Downloads of All Required
Technologies To Run Your System
You MUST Implement Your Database With MySQL
Chapter 10-8
MySQL by Example
CSE
255


MySQL architecture
Online book store implementation via MySQL
 MySQL Administrator
 Command Structures
Defining Tables
and Relational Keys
Insert, update, and delete data
Commit and Rollback


MySQL Data Types
define a simple data model
Show
Manual Construction As Example
Chapter 10-9
MySQL Architecture
CSE
255
http://dev.mysql.com/doc/refman/5.1/en/images/PSEArch.png
Chapter 10-10
Schema Setup via MySQL Administrator
CSE
255
Implement Tables With InnoDB Engine, for Foreign Key
Support and Improved Logging, Compared To MyISAM
Chapter 10-11
MySQL Command Line Client

CSE
255

Interface for Executing Manual Queries And Issuing Commands to MySQL
Note Commands:

show databases;

use <dbName>;

show tables;
Chapter 10-12
Executing Manual Queries
CSE
255
Chapter 10-13
Executing Manual Queries
CSE
255
MySQL Command Line Resource
http://dev.mysql.com/doc/refman/5.0/en/mysql.html
Chapter 10-14
Browsing the catalog

CSE
255
view table structure


DESCRIBE <table>;
view your tables:

SHOW tables;
Chapter 10-15
Schema Administration

CSE
255
MySQL Schema Permissions are Based on Username
 You Must Assign Permissions On a Per Schema Basis
 using other schema’s requires permission (GRANT’s)
Syntax:
http://dev.mysql.com/doc/refman/5.0/en/grant.html
-OR-
Use the MySQL Administrator GUI!
Chapter 10-16
MySQL Administrator

CSE
255

Tool To Prepare Your Database For Access
User Administration
Chapter 10-17
Delete
CSE
255

Delete table with drop table


DROP TABLE customer;
Delete rows with delete from


DELETE FROM customer WHERE name = “Smith”;
DELETE FROM customer;
Chapter 10-18
Commit and Rollback

CSE
255





Modifications of tuples are temporarily stored in the
database
They become permanent after commit; statement has
been issued
You can undo all modifications since last commit using
rollback
Any data definition command like create results in
implicit commit
Termination of MySQL session also executes implicit
commit
Essential For Exception Handling!!
 Try{ SQL(“insert…”); … SQL(“commit”); }
 Catch(Exception){ SQL(“rollback”); }
Chapter 10-19
Things to remember
CSE
255



Always terminate your command with a Semicolon (;)
Exit MySQL Prompt by entering quit or exit at the
mysql> prompt
Commands can be in lower or upper case
Chapter 10-20
MySQL Useful Data types…

CSE
255
character data types :
 varchar(x),
Variable Length




String, where x is size in bytes
For ASCII, UTF-8 formats, 1 character = 1 byte
numerical data:
 INT – implicit size of 32-bits
 DECIMAL[(M[,D])] [UNSIGNED] [ZEROFILL]
Date
 century year month day hour min sec
BLOB (Binary Large Object)
 Data stored as a string of Binary Data
Max
Size: 2^16 bytes
Chapter 10-21
Relational Model

Book

Customer

Order

LineItem
CSE
255
ISBN
Author
Cust #
Title
Name
Order # Cust#
Publisher
Date
Price
Email Street
City
State
Card
Exp.
Auth
Zip
Date
Order# Book#
Chapter 10-22
Create Table
CSE
255
Chapter 10-23
Constraints
CSE
255

Column constraints:
 primary key
 foreign key
 NULL values
 create table CUSTOMER (id NUMBER
CONSTRAINT pk_cust PRIMARY KEY, name
VARCHAR2(250), email VARCHAR2(60)
CONSTRAINT nn_email NOT NULL, addr
NUMBER CONSTRAINT fk_addr REFERENCES
address(id));
Chapter 10-24
Table Constraint Clause
CSE
255
Chapter 10-25
Column Constraint Clause
CSE
255
Chapter 10-26
Schema Creation - book
CSE
255
Examples From SQL*Plus, the Oracle DB Command Line
Tool
But Syntax is the same!
Chapter 10-27
Schema Creation - customer
CSE
255
Chapter 10-28
Schema Creation - order
CSE
255
Chapter 10-29
Schema Creation - line_item
CSE
255
Chapter 10-30
View
CSE
255

Create a new view of data


CREATE VIEW clerk (id_number, person, department,
position) AS SELECT empno, ename, deptno, job FROM
emp WHERE job = 'CLERK’;
Why?
Chapter 10-31
View Command
CSE
255
Chapter 10-32
Alter Table
CSE
255




Add a column, or integrity constraint
Remove an integrity constraint
Cannot rename or drop a column
Keep a copy of the SQL statements you use to create
and alter tables
 ALTER TABLE book MODIFY (price
NUMBER(7,2));
 ALTER TABLE customer DROP PRIMARY KEY
CASCADE;
Chapter 10-33
Alter Table command
CSE
255
Chapter 10-34
Apache Tomcat
CSE
255






An Open-Source Application Server Platform for JSP
Widely Used
 Mac OSX Uses Tomcat for Web Sharing
Provides environment for Java Code To Run In
Cooperation With The Web Server
Includes HTTP Content Server
JSP Pages Are Compiled Via Tomcat As The Page is
Requested
Rich Log-File, Error Handling Output
Chapter 10-35
Tomcat - JSP Connection

CSE
255

Tomcat Must Be Installed On PC That Runs Project To Deliver
Dynamic HTML
 JSP Page With Embedded Java
 Tomcat Compiles JSP, Then Executes Code
 Embedded Java May Output Additional HTML
 Tomcat Inserts Dynamically Generated HTML Into The Page
 HTML Page Delivered To Requesting Entity
Important Resource:
 http://www.coreservlets.com/Apache-TomcatTutorial/index.html#Java-Home
 Recommendation: Download Pre-Configured Package And
Follow Directions
Chapter 10-36
Java Server Pages + Servlets

CSE
255
Servlets
 A Java Object That Receives an HTTP Request and
Generates an HTTP Response
 Usually,
an HTML Document
Like A Standalone Application That Is Always On, Living On
The Application Or Web Server
JSP
 A Definition Of A Java Servlet Program!
Tomcat Compiles the JSP Page Into a Servlet
 The Servlet Executes On the Server



 Sends An

HTTP Reponse At End Of Computation
Compilation is Invisible To User
 URL May
Be http://localhost/Query.jsp
 Displayed Resource: An HTML Document!
Chapter 10-37
JSP

CSE
255
In a nutshell…
 Enables the Embedding of Java Statements In your
HTML
 In JSP page, The stdout Is Now The HTML
Document To Return
Ex:
<HTML>
<BODY>
Hello! The time is now <%= new java.util.Date() %>
</BODY>
</HTML>
<!-<%= //java expression %> : Embedding a Java expression In HTML -->

Cannot Do Much With An Expression…
Chapter 10-38
Scriptlets
CSE
255


A Block Of Java Code Executed Everytime The JSP
Page Is Invoked
Scriptlets Placed In <% … %> brackets
<HTML>
<BODY>
<%
System.out.println( "Evaluating date now" );
java.util.Date date = new java.util.Date();
%>
Hello! The time is now <%= date %>
</BODY>
</HTML>


Variable date is Available In Entire HTML Form!
System.out.println outputs to Server Log
Chapter 10-39
Useful JSP Objects

CSE
255

“out”
 out.println(“HTML”) prints content to HTML
document
 “out” is of type javax.servlet.jsp.JspWriter
“request”
 Object Referring to Transaction Between Browser
And Server
<HTML> <BODY> <% java.util.Date date = new java.util.Date(); %>
Hello! The time is now
<% out.println( date );
out.println( "<BR>Your machine's address is " );
out.println( request.getRemoteHost()); %>
</BODY> </HTML>
Chapter 10-40
Useful JSP Objects

CSE
255
“response”
 Used To Alter HTTP Response Sent To Client Browser
 response.sendRedirect(newURL);
When the HTTP Response For This Page Is Sent, The
Browser Will Instantly Send a Request For newURL!
<HTML>
<% if (!validateUser(userID)){
response.sendRedirect(“loginFailure.jsp”);
}%>
<BODY>
Thanks for Logging In!
</BODY>
</HTML>

Chapter 10-41
Example

CSE
255

Generating an HTML table With Dynamic Number Of
Rows
JSP Fragment:
<TABLE BORDER=2>
<% for ( int i = 0; i < n; i++ ) { %>
<TR>
<TD>Number</TD>
<TD><%= i+1 %></TD>
</TR>
<% } %>
</TABLE>
Chapter 10-42
Conditional HTML
CSE
255


Given Static HTML, Decide To Use It As Output Or
Not
In JSP…
<% if ( hello ) { %>
<P>Hello, world
<% } else { %>
<P>Goodbye, world
<%}%>
Chapter 10-43
JSP Directives
CSE
255



Package Importing
 <%@ page import=“java.util.*, java.text.*” %>
 Good Form: Place Imports Above <HTML> Tag
Directives Are Placed In <%@ … %> Tags
Including Other Files
 <%@ include file=“other.jsp” %>
Useful
for Keeping JSP Pages Clean
Chapter 10-44
JSP Method Declarations
CSE
255

Can Define Methods To Call In Your JSP
 <%!
Date theDate = newDate();
Date getDate(){
return theDate;
}
%>
*Declarations are loaded Once, When The Page Is
First Loaded. On Refresh, theDate Will Not Change!
Suggestion: Declare MySQL Connection, So You Do
Not Restablish Connections On Page Refresh
Chapter 10-45
Attacking The Project

CSE
255

JSP Requires Combination Of
 HTML Development
 Java Development
First Develop Static HTML Pages And Supporting Scripts
 Presentation Tier Development
 Use a Strong IDE If Unfamiliar With HTML
 Dreamweaver
 Visual Studio Express
You Will Get Familiar With HTML As You Create Pages Via
Drag-And-Drop
Then Modify By Hand Static HTML To Include JSP Code
 Application Tier Development
 Eclipse EE Editor Offers Decent Support For JSP Editing
In Parallel Develop Your Data Tier
 Data Model Development (Phase I and II)
 MySQL Implementation And Population (Phase III)



Chapter 10-46
Environment Setup

CSE
255







1. Install Eclipse EE JDK5.0 for JSP editing
2. Install Your HTML Editor Of Choice
3. Install And Configure Tomcat
4. Install And Configure MySQL
5. Install MySQL Administrator
6. Install Connector/J 5.0
 JDBC Connection Driver For MySQL
Test!
 Static HTML
 Simple DHTML
 DHTML That Calls MySQL
 DHTML With JavaScript
Usually…Configuration is Very Unique For A PC
 Research Solutions On Internet To Guide You
Chapter 10-47