Announcements Read JDBC Project Step 5, due Monday.

Slides:



Advertisements
Similar presentations
CSC343 – Introduction to databases – A. Vaisman1 Database Application Development.
Advertisements

Objective: To access a database from an application program (as opposed to interactive interfaces) Why? An interactive interface is convenient but not.
Embedded SQL John Ortiz. Lecture 15Embedded SQL2 Why Isn’t Interactive SQL Enough?  How to do this using interactive SQL?  Print a well-formatted transcript.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Introduction to SQL Programming Techniques.
MSc IT UFIE8K-10-M Data Management Prakash Chatterjee Room 3P16
M.P. Johnson, DBMS, Stern/NYU, Sp20041 C : Database Management Systems Lecture #18 Matthew P. Johnson Stern School of Business, NYU Spring, 2004.
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
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
1 Lecture 29 More on JDBC Overview  Objectives of this lecture  JDBC and its Drivers  Connecting to Databases (Java’s Connection class)  Querying a.
EmbeddedSQL: 1 Impedance Mismatch Problem Problem : How to connect SQL statements with conventional programming languages Different models of language.
JDBC. In This Class We Will Cover: What SQL is What ODBC is What JDBC is JDBC basics Introduction to advanced JDBC topics.
1 Design patterns Lecture 4. 2 Three Important skills Understanding OO methodology Mastering Java language constructs Recognizing common problems and.
Client-server database systems and ODBC l Client-server architecture and components l More on reliability and security l ODBC standard.
Oracle SQL*plus John Ortiz. Lecture 10SQL: Overview2 Overview  SQL: Structured Query Language, pronounced S. Q. L. or sequel.  A standard language for.
1 Foundations of Software Design Lecture 27: Java Database Programming Marti Hearst Fall 2002.
SEMESTER 1, 2013/2014 DB2 APPLICATION DEVELOPMENT OVERVIEW.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
1 Section 6 Embedded SQL. 6-2 CA306 Embedded SQL Section Content 6.1Embedded SQL 6.2Java Database Connectivity 6.3Web Databases.
Getting connected.  Java application calls the JDBC library.  JDBC loads a driver which talks to the database.  We can change database engines without.
CSCI 6962: Server-side Design and Programming
Database System Concepts and Architecture Lecture # 3 22 June 2012 National University of Computer and Emerging Sciences.
PL / SQL P rocedural L anguage / S tructured Q uery L anguage Chapter 7 in Lab Reference.
1 Java Database Connection (JDBC) There are many industrial-strength DBMS's commercially available in the market. Oracle, DB2, and Sybase are just a few.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 David M. Kroenke’s Chapter Seven: SQL for Database Construction and.
© Wang Bin 2004 JDBC ----Java Database Connectivity.
Database Programming in Java Corresponds with Chapter 32, 33.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 9- 1 DATADABASE PROGRAMMING 2Chapter 13 from our text.
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)
Stored procedures1 Stored procedures and functions Procedures and functions stored in the database.
Wednesday, January 14,  Proposed by E.F.Codd in his 1970 paper  Used in System R, IBM’s research relational database in early 1970s-D.D. Chamberlin.
Dr Gordon Russell, Napier University Unit Embedded SQL - V3.0 1 Embedded SQL Unit 5.1.
Advanced SQL: Cursors & Stored Procedures
Copyright  Oracle Corporation, All rights reserved. 7 Accessing a Database Using SQLJ.
SQL in a Programming Environment CIS 4301 Lecture Notes Lecture /11/2006.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 8 Advanced SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Copyright © 2002 ProsoftTraining. All rights reserved. Building Database Client Applications Using JDBC 2.0.
1 CS 430 Database Theory Winter 2005 Lecture 14: Additional SQL Topics.
Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Chapter 4: SQL Complex Queries Complex Queries Views Views Modification of the Database Modification of the Database Joined Relations Joined Relations.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Application Development Chapter 6 Sections –
Chapter 9: Advanced SQL and PL/SQL Guide to Oracle 10g.
Li Tak Sing COMPS311F. Database programming JDBC (Java Database Connectivity) Java version of ODBC (Open Database Connectivity) ODBC provides a standard.
DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
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.
1 Database Application Development Chapter 6 Sections –
Access Databases from Java Programs via JDBC Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale
Basics of JDBC Session 14.
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,
ECMM6018 Enterprise Networking For Electronic Commerce Tutorial 6 CGI/Perl and databases.
SCU Fall 2002JoAnne Holliday10–1 Schedule Today u Triggers, Procedures, PL/SQL. u Read Sections , 8.1, 8.5. Next u Transaction concepts, security.
1 Introduction to Database Systems, CS420 SQL Persistent Stored Modules (PSM) – Stored Procedure.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Application Development Chapter 6.
10/3/2017.
DEPTT. OF COMP. SC & APPLICATIONS
SQL Environment.
Web Technologies IT230 Dr Mohamed Habib.
Database JDBC Overview CS Programming Languages for Web Applications
Chapter 5: Advanced SQL Database System concepts,6th Ed.
Database Application Development
CPSC-310 Database Systems
CPSC-310 Database Systems
Database Application Development
Introduction to SQL Programming Techniques
Chapter 8 Advanced SQL.
Database Application Development
Presentation transcript:

Announcements Read JDBC Project Step 5, due Monday

SQL Database Design Language Lecture 17

Relational Views Can be subsets of base tables, or subsets of joins, or contain calculated data Reasons for views –Allow different users to see the data in different forms –Provide a simple authorization control device –Free users from complicated DML operations –If database is restructured, view can keep the user's model constant

Create View CREATE VIEW viewname [(viewcolname [,viewcolname]...)] AS SELECT colname [,colname]... FROM basetablename [,basetablename]... WHERE condition; Can create vertical subset of table, choosing only certain columns, with no WHERE, called value-independent view Can choose only certain rows, using WHERE, called value-dependent view Can use a join of tables to create view of combination Can use functions in SELECT

Using Views Can write new SQL statements using view name in FROM line Can create a view of a view Can sometimes update a view – requires that the primary key be in the view When user is allowed to update using view, DB administrator can provide an INSTEAD OF trigger to update base tables instead CREATE TRIGGER InsertStuVw2 INSTEAD OF INSERT ON StudentVw2 FOR EACH ROW begin INSERT INTOStudent VALUES (:NEW.stuId, :NEW.lastName, :NEW.firstName, :NEW. Credits); end;

SQL Programming SQL can be embedded in host languages, such as Java, C++, COBOL, and so on Host language can provide control structures, and SQL used for database access Host language statements compiled as usual

Special Java classes Class connects to database Classes for sending statements to the database Class to get results from the database –Powerful enough to allow one to deal with unknown datatypes

Using Cursors Impedance mismatch: SQL SELECT can retrieve multiple rows, while host language requires one row at a time Cursor can be created and positioned to provide one tuple at a time to program Java uses an iterator approach

Dynamic SQL Can create a graphical front end that accepts queries dynamically At run time, user prompted to enter an SQL command Command stored as string PREPARE statement used to parse and compile string and assign it to variable EXECUTE command executes the code

API, ODBC and JDBC DBMS can provide a library of functions available to host languages using an API ODBC/JDBC provide standardized connectivity using a common interface, allows common code to access different databases Most vendors provide ODBC or JDBC drivers that conform to the standard Requires four components: application, driver manager, driver, and data source (database)

ODBC/JDBC Components Application, using the standard API –initiates the connection with the database –submits data requests as SQL statements to the DBMS –retrieves the results –performs processing –terminates the connection Driver manager –loads and unloads drivers at the application’s request –passes the ODBC or JDBC calls to the selected driver Database driver –links the application to the data source –translates the ODBC or JDBC calls to DBMS-specific calls –handles data translation needed because of any differences between the DBMS’s data language and the ODBC/JDBC standard –Controls error handling differences that arise between the data source and the standard. Data source: database (or other source), DBMS and platform; provides the data

SQL/PSM Persistent Stored Modules-used to create internal routines within database space Can be saved with database schema and invoked Oracle uses PL/SQL, accessed within SQLPlus Provides complete programming language facilities-declarations, control, assignment, functions, procedures, temporary relations, etc.

SQL/PSM Procedures and Functions Creating procedures CREATE PROCEDURE procedure_name (parameter_list) declarations of local variables procedure code –Parameters may be IN, OUT, or IN/OUT –Executing procedures-Example: EXECUTE procedure_name(actual_ parameter_ list); Creating functions CREATE FUNCTION function_name (parameter list) RETURNS SQLdatatype declarations of local variables function code (must include a RETURN statement) –Parameters can be IN only, no OUT or IN/OUT –A function is invoked by using its name, typically in an assignment statement..Example: SET newVal = MyFunction(val1, val2);

Declaration, Assignment, Control Statements in SQL/PSM DECLARE identifier datatype; SET number_of_courses = credits/3; IF (condition) THEN statements; ELSEIF (condition) statements; … ELSEIF (condition) statements; ELSE statements; END IF; CASEselector WHEN value1 THEN statements; WHEN value2 THEN statements; … END CASE; LOOP…ENDLOOP, WHILE… DO… END WHILE, REPEAT…UNTIL…END REPEAT, and FOR …DO… END FOR

System Catalog Also called system data dictionary Contains metadata Automatically updated when new database objects created – stores schema Oracle data dictionary provides three views: USER, ALL, and DBA. View invoked by using the appropriate term as a prefix for the object(s) named in the FROM clause in a query –USER view provides a user with information about all the objects created by that user –ALL view provides information about objects user has permission to access in addition to the one the user has created. –DBA view provides information about all database objects; available to the database administrator

Using Oracle Data Dictionary- Examples DESCRIBE STUDENT; DESCRIBE USER_CONSTRAINTS; SELECT CONSTRAINT_NAME, CONSTRAINT_TYPE, TABLE_NAME FROM USER_CONSTRAINTS; SELECT TABLE_NAME FROM USER_TABLES; SELECT VIEW_NAME FROM USER_VIEWS; SELECT TRIGGER_NAME, TRIGGER_EVENT, TRIGGER_TYPE FROM USER_TRIGGERS; SELECT * FROM USER_TAB_COLUMNS; SELECT COLUMN_NAME, DATA_TYPE FROM USER_TAB_COLUMNS WHERE TABLE_NAME = ‘STUDENT’;

Java Classes Connection - to connect to the database Statement - submit query/stat-me to the database –Also Callable Statement – for PL/SQL and PreparedStatement - precompiled statements (more efficient) ResultSet - store results of a query ResultSetMetaData - information about the result set