Database Application Development SQL In Application Code : 1. Embedded SQL 2. Database API’s 3. SQLJ.

Slides:



Advertisements
Similar presentations
ICS 434 Advanced Database Systems
Advertisements

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Introduction to SQL Programming Techniques.
15 Chapter 15 Web Database Development Database Systems: Design, Implementation, and Management, Fifth Edition, Rob and Coronel.
The Application Layer Chapter 7. Electronic Mail Architecture and Services The User Agent Message Formats Message Transfer Final Delivery.
Introduction to Web Database Processing
SPRING 2004CENG 3521 SQL: Constraints, Triggers, Embedded SQL Chapters: 5, 6.
1 C. Shahabi Application Programming for Relational Databases Cyrus Shahabi Computer Science Department University of Southern California
Introduction to Web Interface Technology (CSE2030)
12 Chapter 12 Client/Server Systems Hachim Haddouti.
Introduction to Web Interface Technology (CSE2030)
Chapter 11 ASP.NET JavaScript, Third Edition. 2 Objectives Learn about client/server architecture Study server-side scripting Create ASP.NET applications.
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Internet Applications Chapter 7 Modified by Donghui Zhang.
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Overview of JSP Technology. The need of JSP With servlets, it is easy to – Read form data – Read HTTP request headers – Set HTTP status codes and response.
Database Applications.  Database Programming  Web databases  Application architecture.
1 Web Database Processing. Web Database Applications Static Report Publishing a report is prepared from a database application and exported to HTML DB.
INTRODUCTION TO WEB DATABASE PROGRAMMING
1 Section 6 Embedded SQL. 6-2 CA306 Embedded SQL Section Content 6.1Embedded SQL 6.2Java Database Connectivity 6.3Web Databases.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
_______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications1.
CSCI 6962: Server-side Design and Programming Course Introduction and Overview.
Creating a Basic Web Page
Copyright © cs-tutorial.com. Introduction to Web Development In 1990 and 1991,Tim Berners-Lee created the World Wide Web at the European Laboratory for.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke; edited K. Shomper1 Database Application Development Chapter 6.
Server-side Scripting Powering the webs favourite services.
4-1 INTERNET DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
11/16/2012ISC329 Isabelle Bichindaritz1 Web Database Application Development.
Chapter 17 - Deploying Java Applications on the Web1 Chapter 17 Deploying Java Applications on the Web.
Midterm Exam Chapters 1,2,3,5, 6,7 (closed book) March 11, 2014.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Website Development with PHP and MySQL Saving Data.
1 Welcome to CSC 301 Web Programming Charles Frank.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
ICS 321 Fall 2010 SQL in a Server Environment (i) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 11/1/20101Lipyeow.
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
IS-907 Java EE World Wide Web - Overview. World Wide Web - History Tim Berners-Lee, CERN, 1990 Enable researchers to share information: Remote Access.
Module: Software Engineering of Web Applications Chapter 2: Technologies 1.
CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.
Introduction and Principles Web Server Scripting.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
CP476 Internet Computing Perl CGI and MySql 1 Relational Databases –A database is a collection of data organized to allow relatively easy access for retrievals,
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
1 LM 6 Database Applications Dr. Lei Li. Learning Objectives Explain three components of a client-server system Describe differences between a 2-tiered.
World Wide Web has been created to share the text document across the world. In static web pages the requesting user has no ability to interact with the.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
A Presentation Presentation On JSP On JSP & Online Shopping Cart Online Shopping Cart.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Application Development Chapter 6.
CS320 Web and Internet Programming Database Access with JDBC Chengyu Sun California State University, Los Angeles.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Internet Applications Chapter 7.
National College of Science & Information Technology.
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
INLS 623– Stored Procedures
WWW and HTTP King Fahd University of Petroleum & Minerals
CS320 Web and Internet Programming Database Access with JDBC
Web DB Programming: PHP
Introduction of Week 11 Return assignment 9-1 Collect assignment 10-1
CMPT 354: Database System I
Presentation transcript:

Database Application Development SQL In Application Code : 1. Embedded SQL 2. Database API’s 3. SQLJ

SQL in Application Code SQL commands can be called from within a host language (e.g., C++ or Java) program. SQL statements can refer to host variables (including special variables used to return status). Must include a statement to connect to the right database Two main integration approaches: Embed SQL in the host language (Embedded SQL, SQLJ) Create special API to call SQL commands (JDBC)

Embedded SQL Approach: Embed SQL in the host language. A preprocessor converts the SQL statements into special API calls. Then a regular compiler is used to compile the code. Language constructs: Connecting to a database: EXEC SQL CONNECT Declaring variables: EXEC SQL BEGIN (END) DECLARE SECTION

Embedded SQL Language Constructs (cntd.) Statements: EXEC SQL Statement; Variables: (Two special “error” variables, one of them must be declared) SQLCODE (long, is negative if an error has occurred) SQLSTATE (char[6], predefined codes for common errors)

Database API’s Alternative to embedding Rather than modify compiler, add library with database calls (API) Special standardized interface: Procedures/objects Pass SQL strings from language, presents result sets in a language-friendly way

Database API’s Sun’s JDBC: Java API Supposedly DBMS-neutral, a “driver” traps the calls and translates them into DBMS specific code Database can be across a network DBMS independent both at the source code and executable level.

JDBC Architecture JDBC architecture has four components: Application (initiates and terminates connections, submits SQL statements) Driver manager (load JDBC driver) Driver (connects to data source, transmits requests and returns/translates results and error codes) Data source (processes SQL statements)

JDBC Architecture Steps to submit a database query: Load the JDBC driver Connect to the data source Execute SQL statements

Example Code Step 1: Include necessary Java packages import java.sql.*; Step 2: Load the corresponding JDBC driver for the data source you want to connect. Class.forName("com.mysql.jdbc.Driver");

Example Code We interact with a data source through sessions. Each connection identifies a logical session. Connnections are specified through a JDBC URL in the following form: jdbc: : e.g. : String url = " jdbc:oracle://knuth.ug.bcc.bilkent.edu.tr/test "

Example Code Now, we want to create and execute SQL statements. In JDBC, there are three different ways of executing statements: Statement, PreparedStatement and Callable Statement. We can simply use a Statement for a query, and use ResultSet object to handle the query result. First, let’s declare and create a Statement object. Statement selectStmt; selectStmt = con.createStatement();

Example Code Notice that we will handle the result by using a ResultSet object, similar to a cursor. ResultSet rs; Execute the query rs = selectStmt.executeQuery("SELECT * FROM employee");

Example Code Now, you can read values from each tuple and do something with them while(rs.next()) { System.out.print(“Emp no:” + rs.getInt(1) +" "); System.out.print(“Emp name:”+ rs.getString(2)”+ " "); … }

Example Code For a PreparedStatement, the structure is fixed but values of parameters are determined at the run time. First, determine your query structure String sql_string= "INSERT INTO employee VALUES (?,?,?,?,?,?,?,?,?)“ Create the prepared statement PreparedStatement pstmt = con.prepareStatement (sql_string);

Example Code Now, we instantiate the parameters with values pstmt.clearParameters(); pstmt.setInt(1,100); pstmt.setString(2, “john”); pstmt.setString(3, “manager”); Submit the query to the data source. pstmt.executeUpdate();

SQL J Complements JDBC with a (semi-)static query model. Compiler can perform syntax checks, strong type checks, consistency of the query with the schema. SQLJ is a part of the SQL standard whereas embedded SQL is vendor-specific.

Internet Applications

URI URI (Uniform Resource Identifier): Uniform naming schema to identify resources on the Internet. e.g : URI has three parts: Naming schema (http) Name of the host computer ( Name of the resource (~dbbook/index.html) URLs are a subset of URIs

HTTP (HyperText Transfer Protocol) Client (web browser) sends HTTP request to server Server receives request and replies Client receives reply; makes new requests

HTTP (HyperText Transfer Protocol) Note that, HTTP is stateless: No “sessions” Every message is completely self-contained No previous interaction is “remembered” by the protocol

Web Data Formats HTML: The presentation language for the Internet. HTML is a markup language. Commands are tags XML: A self-describing, hierarchal data model DTD: Standardizing schemas for Xml

Web Data Formats XML – The Extensible Markup Language Language: A way of communicating information Markup: Notes or meta-data that describe your data or language Extensible: Limitless ability to define new languages or data sets

Web Data Formats The point is that you can include your data and a description of what the data represents. This is useful for defining your own language or protocol e.g. Chemical Markup Language …

Components of Data-Intensive Systems Three separate types of functionality: Data management Application logic Presentation The system architecture determines whether these three components reside on a single system (“tier) or are distributed across several tiers.

The Three-Tier Architecture The Three Layers Presentation tier Primary interface to the user Needs to adapt to different display devices (PC, PDA, cell phone, voice access?) Middle tier Implements business logic (implements complex actions, maintains state between different steps of a workflow) Accesses different data management systems Data management tier One or more standard database management systems

The Three-Tier Architecture A course enrollment system: Database System: Student info, course info, instructor info, course availability, pre-requisites, etc. Application Server: Logic to add a course, drop a course, create a new course, etc. Client Program Log in different users (students, staff, faculty), display forms and human-readable output

Presentation Tier HTML Forms: How to pass data to the middle tier JavaScript: Simple functionality at the presentation tier Style sheets: Separating data from formatting

Presentation Tier - HTML Forms Common way to communicate data from client to middle tier. General format of a form: … Components of an HTML FORM tag: ACTION: Specifies URI that handles the content METHOD: Specifies HTTP GET or POST method NAME: Name of the form; can be used in client-side scripts to refer to the form.

Presentation Tier - HTML Forms Inside HTML forms, there may be the INPUT tag. It has the following attributes: TYPE: text (text input field), password (text input field where input is displayed as stars), reset (resets all input fields) NAME: symbolic name, used to identify field value at the middle tier. VALUE: default value

Presentation Tier - HTML Forms Example : A form that has two text input fields, one submit and one reset button.

Presentation Tier - HTML Forms Passing Arguments Two methods: GET and POST. Form contents go into the submitted URI. Structure: action?name1=value1&name2=value2&name3=value3 Action: Name of the URI specified in the form. Note that the page named action needs to be a program, script, or page that will process the user input (name,value)-pairs: These come from INPUT fields in the form; empty fields have empty values (“name=“) e.g. Welcome.jsp?userid=john&password=johnpw

Presentation Tier - JavaScript Goal: Add functionality to the presentation tier. Sample applications: Detect browser type and load browser-specific page Form validation: Validate form input fields Browser control: Open new windows, close existing windows (example: pop-up ads) Usually embedded directly inside the HTML with the … tag.

Middle Tier Encodes business logic Connects to database system(s) Accepts form input from the presentation tier Generates output for the presentation tier.

Middle Tier Technologies: CGI: Protocol for passing arguments to programs running at the middle tier Application servers: Runtime environment at the middle tier Servlets: Java programs at the middle tier JavaServerPages: Java scripts at the middle tier PHP: PHP scripts at the middle tier.

Middle Tier - PHP PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. PHP Test <?php echo ' Hello World '; ?>

Middle Tier - PHP EXAMPLE PAGE Hello World!!! This is my first PHP script as a CS352 student.... Here is the list of all employees in our company database: <?php.....

Middle Tier - PHP <?php // Connect to server where your DB is, login and password to the DBMS (Here it is MySQL) $connection = mysql_connect(' ','company_user','123'); // Give an error if you can not connect if(!connection) die("Could not connect");....

Middle Tier - PHP // Choose the database among those databases to use. As a //company_user, we are allowed to use the company database. mysql_select_db('company');

Middle Tier - PHP // Prepare a query string, just like we have done in Java $query = "SELECT * FROM Employee"; // Send & execute the query, again this is similar to saying: // "ResultSet rs =stmt.executeQuery($query)" in our java //example $result = mysql_query($query); // This counts the number of tuples in the result $result_no = mysql_num_rows($result);

Middle Tier - PHP // if some results are found, write them if ($result_no >0) { for($i = 1; $i<=$result_no; $i++) { // Fetch the contents of current record into the variables $employee_no, etc. list($employee_no, $name…) = mysql_fetch_row($result); // This is to write the output to HTML so that it is viewed by the browser echo "NO: $employee_no NAME: $name SKILL: $skill …“; echo " "; }

Middle Tier - PHP // If no results are found else echo “no employee in the company database” // Close the php tag ?> //Close the body and html tags

Maintaining State in HTTP HTTP is stateless. Advantages Easy to use: don’t need anything Great for static-information applications Requires no extra memory space Disadvantages No record of previous requests means No shopping baskets or user logins No custom or dynamic content Security is more difficult to implement

Maintaining State in HTTP Server-side state: Information is stored in a database, or in the application layer’s local memory Client-side state: Information is stored on the client’s computer in the form of a cookie Hidden state: Information is hidden within dynamically created web pages

The material discussed in this document is summarized from the slides of the textbook (Chapter 7)“Database Management Systems” by Ramakrishnan and Gehrke, 3 rd Edition.