SCU Fall 2002JoAnne Holliday10–1 Schedule Today u Embedded SQL. u Read Sections 8.1, 8.5. Next u Transaction concepts, security u Read Sections 8.6 – 8.7.

Slides:



Advertisements
Similar presentations
Definition Cursor is a control structure for the successive traversal of records in a result set. Cursor is a record pointer in a database. DATABASE CURSOR.
Advertisements

1 Database-Connection Libraries Call-Level Interface Java Database Connectivity PHP.
Chapter 9 SQL in a Server Environment Call-Level Interface Java Database Connectivity PHP.
1 Combining SQL and Conventional Programming Languages Source: slides by Jeffrey Ullman.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Introduction to SQL Programming Techniques.
Fall 2001Arthur Keller – CS 18011–1 Schedule Oct. 30 (T) Embedded SQL. u Read Section 8.1. u Assignment 5 due. Not accepted late. u Project Part 4 due.
1 JDBC Java Database Connectivity. 2 c.pdf
1 SQL/PSM Procedures Stored in the Database General-Purpose Programming.
Winter 2002Arthur Keller – CS 18011–1 Schedule Today: Feb. 7 (TH) u PL/SQL, Embedded SQL, CLI, JDBC. u Read Sections 8.1, Feb. 12 (T) Advising.
1 SQL Programming Embedded SQL Call-Level Interface Java Database Connectivity Persistent Stored Modules.
Getting connected.  Java application calls the JDBC library.  JDBC loads a driver which talks to the database.  We can change database engines without.
1 CSC 440 Database Management Systems JDBC This presentation uses slides and lecture notes available from
1 Real SQL Programming Persistent Stored Modules (PSM) PL/SQL Embedded SQL.
CS411 Database Systems Kazuhiro Minami 07: SQL System Aspects.
CSCI 6962: Server-side Design and Programming JDBC Database Programming.
Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 9- 1 DATADABASE PROGRAMMING 2Chapter 13 from our text.
1 Real SQL Programming Embedded SQL Call-Level Interface Java Database Connectivity.
Chapter 8 Using SQL in an Application. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 8-2 CSC 4480 outline Intro (3-9) Static SQL (10-11)
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Modification of the Database – Deletion Delete all tuples from the loan relation. delete.
JDBC Enterprise Systems Programming. JDBC  Java Database Connectivity  Database Access Interface provides access to a relational database (by allowing.
1 Real SQL Programming Persistent Stored Modules (PSM) PL/SQL Embedded SQL.
1 Real SQL Programming Embedded SQL Java Database Connectivity Stored Procedures.
Winter 2006 Keller, Ullman, Cushing 11–1 Embedded SQL Add to a conventional programming language (C in our examples) certain statements that represent.
Chapter 4: SQL Complex Queries Complex Queries Views Views Modification of the Database Modification of the Database Joined Relations Joined Relations.
JDBC CS 124. JDBC Java Database Connectivity Database Access Interface provides access to a relational database (by allowing SQL statements to be sent.
JDBC By 朱志興. Four driver types of JDBC (1) JDBC-ODBC bridge plus ODBC driver: Java Database Client JDBC- ODBC bridge ODBC driver Database Server A B C.
Dr Gordon Russell, Napier University Unit Embedde SQL - V2.0 1 Embedded SQL Unit 5.1.
1 Real SQL Programming Persistent Stored Modules (PSM) PL/SQL Embedded SQL.
Chapter 4 An Introduction to SQL. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.4-2 Topics in this Chapter SQL: History and Overview The.
16 Java Database Connectivity. 2 Understand the JDBC Understand the steps of the JDBC: 1.) Importing packages 2.) Opening a connection to a database 3.)
Database Access Using JDBC BCIS 3680 Enterprise Programming.
SQL Programming SQL in Application Programs
SCU Fall 2002JoAnne Holliday10–1 Schedule Today u Triggers, Procedures, PL/SQL. u Read Sections , 8.1, 8.5. Next u Transaction concepts, security.
Introduction to JDBC Instructor: Mohamed Eltabakh 1.
RETRIEVE A NO. OF ROWS ¦ Declare a cursor ¦ Open the cursor ¦ Fetch rows of data ¦ Stop fetching rows ¦ Close the cursor.
Chapter 7: Constraints and Triggers Foreign Keys Local and Global Constraints Triggers 1.
1 Database Design: DBS CB, 2 nd Edition SQL in a Server Environment: CLI & JDBC & Security Ch Ch. 9.6 – Ch 10.1.
1 Database Design: DBS CB, 2 nd Edition SQL in a Server Environment: Stored Procedure & Embedded SQL Ch. 9.3, 9.4.
1 Introduction to Database Systems, CS420 SQL Persistent Stored Modules (PSM) – Stored Procedure.
JDBC Statements The JDBC Statement, CallableStatement, and PreparedStatement interfaces define the methods and properties that enables to send SQL or PL/SQL.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
SQL in the real world 1. The Three-Tier Architecture of Database Applications browser network HTTP Web server Application server Database server database.
Chapter 4 An Introduction to SQL. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.4-2 Topics in this Chapter SQL: History and Overview The.
SQL in the real world 1. The SQL Client-Server Interactions SQL-clientSQL-server Environment SQL-agent Module Connection Session Current catalog and schema.
Database Design and Programming Jan Baumbach Adopted from previous slides of Peter Schneider-Kamp.
JSP and DB.
Database: JDBC Overview
Chapter 4 An Introduction to SQL.
Chap 8. SQL in a Server Environment-PartIII
1st Semester, 2017 Sanghyun Park
SQL Environment.
Introduction to Database Systems, CS420
Database Design and Programming
JDBC – Java Database Connectivity
CS320 Web and Internet Programming Database Access with JDBC
Database JDBC Overview CS Programming Languages for Web Applications
Database Design and Programming
Chapter 5: Advanced SQL Database System concepts,6th Ed.
CPSC-310 Database Systems
Basic Structure of SQL The basic structure of an SQL expression consists of three clauses: The select clause corresponds to the projection operation of.
CPSC-310 Database Systems
Unit I-2.
Java Database Connectivity
Persistent Stored Modules (PSM) PL/SQL Embedded SQL
Dynamic SQL The dynamic SQL component of SQL allows programs to construct and submit SQL queries at run time. In contrast, embedded SQL statements must.
JDBC Example.
Database-Connection Libraries
CPSC-608 Database Systems
Embedded SQL Chapter 8.
Presentation transcript:

SCU Fall 2002JoAnne Holliday10–1 Schedule Today u Embedded SQL. u Read Sections 8.1, 8.5. Next u Transaction concepts, security u Read Sections 8.6 – 8.7

SCU Fall 2002JoAnne Holliday10–2 Embedding SQL in a Host Language The cursor area is an area for the results of select statements that result in multiple rows. The cursor pointer is a pointer to a row in the collection of rows retrieved by a SQL query. Example: From within a host language, find the names and account numbers of customers with more than the variable amt dollars in some account.

SCU Fall 2002JoAnne Holliday10–3 Embedding SQL First, declare a cursor and specify the query in SQL: EXEC SQL declare c cursor for select customer-name, account# from Depositor, Account where Depositor.account#=Account.account# andAccount.balance > :amt END-EXEC This defines the cursor c.

SCU Fall 2002JoAnne Holliday10–4 Embedded SQL The query is not done until you do an open, then the query is done and the result is put into the cursor area. (The result may be larger than the actual buffer that is allocated as cursor c. The system takes care of that.) EXEC SQL open c END-EXEC

SCU Fall 2002JoAnne Holliday10–5 Embedded SQL You can only look at a single row at a time. This is done with the fetch statement. If cn and an are variables in the host language, this will cause the values of one row in the result to be placed in the variables: EXEC SQL fetch c into :cn :an END-EXEC

SCU Fall 2002JoAnne Holliday10–6 Embedded SQL Repeated calls to fetch get successive rows in the query result. The close statement causes the database system to delete the temporary relation that holds the results of the query. EXEC SQL close c END-EXEC

SCU Fall 2002JoAnne Holliday10–7 Using Java and JDBC Start with a Connection object, unique to DBMS and installation (see web page). Method createStatement() returns an object of class Statement (if there is no argument) or PreparedStatement if there is an SQL statement as argument.

SCU Fall 2002JoAnne Holliday10–8 JDBC Statement stat1 = myCon.createStatement(); PreparedStatement stat2 = myCon.createStatement( "SELECT beer, price " + "FROM Sells" + "WHERE bar = 'Joe''s Bar'" ); myCon is a connection, stat1 is an “empty” statement object, and stat2 is a (prepared) statement object that has an SQL statement associated.

SCU Fall 2002JoAnne Holliday10–9 Executing Statements JDBC distinguishes queries (statements that return data) from updates (statements that only affect the database). Methods executeQuery() and executeUpdate() are used to execute these two kinds of SQL statements. u They must have an argument if applied to a Statement, never if applied to a PreparedStatement. When a query is executed, it returns an object of class ResultSet.

SCU Fall 2002JoAnne Holliday10–10 Example stat1.executeUpdate( "INSERT INTO Sells" + "VALUES('Brass Rail', 'Bud', 3.00)" ); ResultSet Menu = stat2.executeQuery();

SCU Fall 2002JoAnne Holliday10–11 Getting the Tuples of a ResultSet Method Next() applies to a ResultSet and moves a “cursor” to the next tuple in that set. u Apply Next() once to get to the first tuple.  Next() returns FALSE if there are no more tuples. While a given tuple is the current of the cursor, you can get its ith component by applying to a ResultSet a method of the form get X (i), where X is the name for the type of that component.

SCU Fall 2002JoAnne Holliday10–12 Example while(Menu.Next()) { theBeer = Menu.getString(1); thePrice = Menu.getFloat(2);... }