PPT

6,033 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
6,033
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
30
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Create multiple tabless/views/grants Atomic action
  • schema - is the schema to contain the table. Default to own schema. OR REPLACE - recreates the view if it already exists. You can use this option to change the definition of an existing view without dropping, recreating, and regranting object privileges previously granted to it. FORCE - creates the view regardless of whether the view's base tables exist or the owner of the schema containing the view has privileges on them. Note that both of these conditions must be true before any SELECT, INSERT, UPDATE, or DELETE statements can be issued against the view. NOFORCE - creates the view only if the base tables exist and the owner of the schema containing the view has privileges on them. The default is NOFORCE. view - is the name of the view. alias - specifies names for the expressions selected by the view's query. The number of aliases must match the number of expressions selected by the view. AS subquery - WITH CHECK OPTION - specifies that inserts and updates performed through the view must result in rows that the view query can select. The CHECK OPTION cannot make this guarantee if there is a subquery in the query of this view or any view on which this view is based. CONSTRAINT - is the name assigned to the CHECK OPTION constraint.
  • PPT

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

    ×