© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 31.1 Reviewing the Bookstore Application 31.2.

Slides:



Advertisements
Similar presentations
CE203 - Application Programming Autumn 2013CE203 Part 51 Part 5.
Advertisements

 2003 Prentice Hall, Inc. All rights reserved. Chapter 24: Servlets Outline 24.1 Introduction 24.2 Servlet Overview and Architecture Interface.
Java Database Connectivity (JDBC). 2/24 JDBC (Java DataBase Connectivity) - provides access to relational database systems JDBC is a vendor independent.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Multiple Tiers in Action
Apache Tomcat Server Typical html Request/Response cycle
Getting Started with Microsoft SQL Server 2012 Express Edition Appendix A DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 6 th Edition.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 23: Java Database Connectivity with JDBC Outline 23.1 Introduction 23.2 Relational-Database Model.
Proposed Website By Raymond Chieng and Tim. This website design is based on a local Chinese restaurant which basically need to facilitate online ordering.
Getting Started with Oracle Database 11g Release 2 Express Edition Appendix B DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 6 th Edition.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 37 - JavaServer Pages (JSP): Bonus for Java Developers Outline 37.1 Introduction 37.2 JavaServer.
 2002 Prentice Hall. All rights reserved. JavaServer Pages.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
CSCI 6962: Server-side Design and Programming
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Bookstore Web Application Introducing Visual Web Developer 2008 Express and the.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 29.1 Multi-Tier Architecture 29.2 Web Servers.
CSCI 6962: Server-side Design and Programming JDBC Database Programming.
Jaeki Song JAVA Lecture 11 Java Database Connectivity.
Database Programming in Java Corresponds with Chapter 32, 33.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
INSERT BOOK COVER 1Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Microsoft Office Access 2010 by Robert Grauer, Keith.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Introducing Web Controls Outline 29.1 Analyzing the.
CIS 270—Application Development II Chapter 25—Accessing Databases with JDBC.
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 30 – Bookstore Application: Client Tier Introducing.
Active Server Pages ASP is Microsoft’s server-side script engine for dynamically-generated web pages. Most common language used is VBScript. If you use.
Java Server Pages A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format,
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 8 - Interest Calculator Application: Introducing.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 38 Advanced Java Database.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L12_JDBC_MySQL 1 MySQL and JDBC.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 30 – Bookstore Application: Client Tier Examining.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 27 - Phone Book Application Introducing Multimedia.
Java Servlets Outline 24.1 Introduction 24.2 Servlet Overview and Architecture Interface Servlet and the Servlet Life Cycle HttpServlet Class.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 23: Java Database Connectivity with JDBC Outline 23.1 Introduction 23.2 Relational-Database Model.
Domain Driven Web Development With WebJinn Sergei Kojarski College of Computer & Information Science Northeastern University joint work with David H. Lorenz.
Mark Dixon 1 09 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 32.1 Reviewing the Bookstore Application 32.2.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 33 Advanced Java.
JSP program that interacts with HTML form & Access Data Base.
Accessing Database using JDBC. JDBC Objectives Gain basic knowledge of Java JDBC Become familiar with the basics of interacting with a database using.
Domain Driven Web Development With WebJinn Sergei Kojarski College of Computer & Information Science Northeastern University joint work with David H. Lorenz.
Copyright  Oracle Corporation, All rights reserved. 7 Accessing a Database Using SQLJ.
Jsp (Java Server Page) Is a server side program.
Copyright © 2002 ProsoftTraining. All rights reserved. Building Database Client Applications Using JDBC 2.0.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Bookstore Application: Middle Tier Introducing Code-Behind Files, Session State.
DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
EXAMPLE I An application showing JDBC access to Cloudscape.
Chapter Fourteen Access Databases and SQL Programming with Microsoft Visual Basic th Edition.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
 2002 Prentice Hall. All rights reserved. 9.8 Multi-Tier Applications: Using JDBC from a Servlet Three-tier distributed applications –User interface –Business.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 24: Servlets Outline 24.1 Introduction 24.2 Servlet Overview and Architecture Interface.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 24.1 Test-Driving the Enhanced Car Payment.
Connecting to MySQL using Java By:. – Required to use Java.sql so that we can use Connection and Queries using strings. – Javax.swing.* needed for components.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 2 – Welcome Application Introduction to Graphical.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
Database Processing Applications Chapter Seven DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 7 th Edition.
Database Processing with JSP ISYS 350. Database Applications Applications Database Server Queries/Updates Results.
A Presentation Presentation On JSP On JSP & Online Shopping Cart Online Shopping Cart.
CS320 Web and Internet Programming Database Access with JDBC Chengyu Sun California State University, Los Angeles.
Active Server Pages ASP is Microsoft’s server-side script engine for dynamically-generated web pages. Most common language used is VBScript. If you use.
Copyright © 2008 Pearson Prentice Hall Inc.
Copyright © 2008 Pearson Prentice Hall Inc.
Copyright © 2008 Pearson Prentice Hall Inc.
Copyright © 2008 Pearson Prentice Hall Inc.
Lecture 11 Database Connection
Copyright © 2008 Pearson Prentice Hall Inc.
Presentation transcript:

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 31.1 Reviewing the Bookstore Application 31.2 Information Tier: Database 31.3 Using the Cloudscape Database in JSP Pages 31.4 Wrap-Up Tutorial 31 – Bookstore Application: Information Tier Examining the Database and Creating Database Components

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 2 Objective In this tutorial, you will learn to: –Connect to a database. –Create SQL statements that retrieve information from a database.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Reviewing the Bookstore Application When the books.jsp page is requested Retrieve the book titles from the database Display the book titles in an HTML menu If the user selects a book title from the menu and clicks the View Information (submit) button Request the bookInformation.jsp page for the selected title When the bookInformation.jsp page is requested from books.jsp Retrieve the selected book’s information from a database for the selected title Format the retrieved information in the bookInformation.jsp page Return the result to the client browser If the user clicks the Book List link on the bookInformation.jsp page Request the books.jsp page

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Reviewing the Bookstore Application (Cont.)

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Reviewing the Bookstore Application (Cont.)

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Information Tier: Database Products table –Nine columns –productID, title, authors, copyrightYear, edition, isbn, cover, description and price

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Information Tier: Database

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using the Cloudscape Database in JSP Pages Scriptlet (scripting element) –Block of Java code in a JSP – JSP comment –

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using the Cloudscape Database in JSP Pages (Cont.) Figure 31.4 Adding the template for the JSP scriptlet. JSP commentsStart JSP scriptlet Java code inside the scriptlet End JSP scriptlet

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using the Cloudscape Database in JSP Pages (Cont.) Figure 31.5 Setting the location of the database. Specifying database location setProperty method Specifies database location Escape sequence \\

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using the Cloudscape Database in JSP Pages (Cont.) Figure 31.6 Loading the database driver. Loading database driver class

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using the Cloudscape Database in JSP Pages (Cont.) Figure 31.7 Connecting to the database. Connecting to bookstore database Connection object –Connects to the bookstore database

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using the Cloudscape Database in JSP Pages (Cont.) Figure 31.8 Creating a Statement object. Creating Statement object to execute SQL statement Statement object –Use the database connection to execute SQL statements

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using the Cloudscape Database in JSP Pages (Cont.) Figure 31.9 Getting information from the database. Executing query to get book titles executeQuery method –Retrieve information from the database

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using the Cloudscape Database in JSP Pages (Cont.) Figure Closing the connection to the database. Closing database connection

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using the Cloudscape Database in JSP Pages (Cont.) Figure Ending the JSP scriptlet and catching exceptions. out object –implicit objects –println method Displaying error message

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using the Cloudscape Database in JSP Pages (Cont.) Figure Running the updated books.jsp page.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using the Cloudscape Database in JSP Pages (Cont.) Figure Adding the template for the JSP scriptlet. Adding JSP scriptlet

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using the Cloudscape Database in JSP Pages (Cont.) Figure Setting the location of the database. Specifying database location

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using the Cloudscape Database in JSP Pages (Cont.) Figure Loading the database driver. Loading database driver class

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using the Cloudscape Database in JSP Pages (Cont.) Figure Creating the JDBC connection. Connecting to bookstore database

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using the Cloudscape Database in JSP Pages (Cont.) Figure Creating the Statement object. Creating Statement object to execute an SQL statement

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using the Cloudscape Database in JSP Pages (Cont.) Figure Creating the Statement object. request object –getParameter method Executing query to get book information

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using the Cloudscape Database in JSP Pages (Cont.) Figure Ending the scriptlet so that literal HTML markup can be inserted in the response to the client. Ending JSP scriptlet

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using the Cloudscape Database in JSP Pages (Cont.) Figure Closing the database connection. Continuing the JSP scriptlet Java code inside the scriptlet that closes the database connection and displays error message if exception occurs Ending JSP scriptlet

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using the Cloudscape Database in JSP Pages (Cont.) Figure Running the updated bookInformation.jsp page.

 2004 Prentice Hall, Inc. All rights reserved. Outline Book List Available Books books.jsp (1 of 4)

 2004 Prentice Hall, Inc. All rights reserved. Outline Select a book from the list and click the button to view 25 the selected book's information <% 32 // setup database connection 33 try 34 { 35 // specify database location 36 System.setProperty( "db2j.system.home", 37 "C:\\Examples\\Tutorial29\\Databases" ); // load Cloudscape driver 40 Class.forName( "com.ibm.db2j.jdbc.DB2jDriver" ); // connect to bookstore database 43 Connection connection = 44 DriverManager.getConnection( 45 "jdbc:db2j:bookstore" ); 46 books.jsp (2 of 4) JSP comment Start JSP scriptlet Specifying database location Loading database driver class Connecting to the bookstore database

 2004 Prentice Hall, Inc. All rights reserved. Outline // obtain list of titles 48 if ( connection != null ) 49 { 50 Statement statement = 51 connection.createStatement(); ResultSet results = statement.executeQuery( 54 "SELECT title FROM Products" ); // close database connection 57 connection.close(); } // end if } // end try // catch SQLException 64 catch( SQLException exception ) 65 { 66 out.println( 67 "Exception: " + exception + " occurred." ); 68 } %> 71 books.jsp (3 of 4) Creating Statement to execute SQL query Executing query to get book titles Closing database connection Displaying error message End JSP scriptlet

 2004 Prentice Hall, Inc. All rights reserved. Outline books.jsp (4 of 4)

 2004 Prentice Hall, Inc. All rights reserved. Outline Book Information <% bookInformation.jsp (1 of 4) JSP comment Start JSP scriptlet

 2004 Prentice Hall, Inc. All rights reserved. Outline // setup database connection 26 try 27 { 28 // specify database location 29 System.setProperty( "db2j.system.home", 30 "C:\\Examples\\Tutorial29\\Databases" ); // load Cloudscape driver 33 Class.forName( "com.ibm.db2j.jdbc.DB2jDriver" ); // obtain connection to database 36 Connection connection = DriverManager.getConnection( 37 "jdbc:db2j:bookstore" ); // obtain list of titles from database 40 if ( connection != null ) 41 { 42 // create statement 43 Statement statement = connection.createStatement(); // execute query to get book information bookInformation.jsp (2 of 4) Specifying database location Loading database driver class Connecting to the bookstore database Creating Statement to execute SQL query

 2004 Prentice Hall, Inc. All rights reserved. Outline ResultSet results = statement.executeQuery( 47 "SELECT cover, title, authors, price, " + 48 "isbn, edition, copyrightYear, description " + 49 "FROM Products WHERE title = '" + 50 request.getParameter( "bookTitle" ) + "'" ); %> Authors: Price: ISBN: Edition: Copyright Year: bookInformation.jsp (3 of 4) Executing query to get book information End JSP scriptlet to begin inserting literal HTML markup

 2004 Prentice Hall, Inc. All rights reserved. Outline Description: Book List <% // continue scriptlet connection.close(); // close database connection } // end if } // end try // catch SQLException 87 catch( SQLException exception ) 88 { 89 out.println( "Exception: " + exception + " occurred." ); 90 } %> bookInformation.jsp (4 of 4) Continue JSP scriptletEnd JSP scriptlet