CS346: Database Programming. http://warwick.ac.uk/cs346



Similar documents
Chapter 13. Introduction to SQL Programming Techniques. Database Programming: Techniques and Issues. SQL Programming. Database applications

More SQL: Assertions, Views, and Programming Techniques

CS 377 Database Systems SQL Programming. Li Xiong Department of Mathematics and Computer Science Emory University

The JAVA Way: JDBC and SQLJ

Course Objectives. Database Applications. External applications. Course Objectives Interfacing. Mixing two worlds. Two approaches

Database Programming. Week *Some of the slides in this lecture are created by Prof. Ian Horrocks from University of Oxford

Database Access from a Programming Language: Database Access from a Programming Language

Database Access from a Programming Language:

SQL Programming. CS145 Lecture Notes #10. Motivation. Oracle PL/SQL. Basics. Example schema:

What is ODBC? Database Connectivity ODBC, JDBC and SQLJ. ODBC Architecture. More on ODBC. JDBC vs ODBC. What is JDBC?

Using ORACLE in the CSLab

SQL: Programming. Introduction to Databases CompSci 316 Fall 2014

Chapter 9, More SQL: Assertions, Views, and Programming Techniques

SQL/PSM. Outline. Database Application Development Oracle PL/SQL. Why Stored Procedures? Stored Procedures PL/SQL. Embedded SQL Dynamic SQL

Real SQL Programming 1

COSC344 Database Theory and Applications. Java and SQL. Lecture 12

JDBC (Java / SQL Programming) CS 377: Database Systems

Oracle8/ SQLJ Programming

Programming Database lectures for mathema

Why Is This Important? Database Application Development. SQL in Application Code. Overview. SQL in Application Code (Contd.

Oracle Database: SQL and PL/SQL Fundamentals

CSC 443 Database Management Systems. The SQL Programming Language

Real SQL Programming. Persistent Stored Modules (PSM) PL/SQL Embedded SQL

Database Access via Programming Languages

Oracle Database: SQL and PL/SQL Fundamentals NEW

Database Extension 1.5 ez Publish Extension Manual

Real SQL Programming. Embedded SQL Call-Level Interface Java Database Connectivity

SQL and Java. Database Systems Lecture 19 Natasha Alechina

Mimer SQL. Programmer s Manual. Version 8.2 Copyright 2000 Mimer Information Technology AB

Database Application Development. Overview. SQL in Application Code. Chapter 6

DEVELOPING MULTITHREADED DATABASE APPLICATION USING JAVA TOOLS AND ORACLE DATABASE MANAGEMENT SYSTEM IN INTRANET ENVIRONMENT

SQL and Programming Languages. SQL in Programming Languages. Applications. Approaches

Oracle 11g PL/SQL training

Java Application Developer Certificate Program Competencies

Using Netbeans and the Derby Database for Projects Contents

Overview. Database Application Development. SQL in Application Code (Contd.) SQL in Application Code. Embedded SQL. Embedded SQL: Variables

Services. Relational. Databases & JDBC. Today. Relational. Databases SQL JDBC. Next Time. Services. Relational. Databases & JDBC. Today.

PHP Language Binding Guide For The Connection Cloud Web Services

Oracle Database: SQL and PL/SQL Fundamentals

Java and Databases. COMP514 Distributed Information Systems. Java Database Connectivity. Standards and utilities. Java and Databases

Querying Databases Using the DB Query and JDBC Query Nodes

Supplement IV.C: Tutorial for Oracle. For Introduction to Java Programming By Y. Daniel Liang

Visual Basic. murach's TRAINING & REFERENCE

FileMaker 11. ODBC and JDBC Guide

A Generic Database Web Service

Java SE 8 Programming

Penetration Testing: Advanced Oracle Exploitation Page 1

SINGLE SIGNON FUNCTIONALITY IN HATS USING MICROSOFT SHAREPOINT PORTAL

Configuring an Alternative Database for SAS Web Infrastructure Platform Services

An Introduction to SQL Injection Attacks for Oracle Developers. January 2004 INTEGRIGY. Mission Critical Applications Mission Critical Security

14 Triggers / Embedded SQL

Using SQL Developer. Copyright 2008, Oracle. All rights reserved.

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to:

5.1 Database Schema Schema Generation in SQL

Exploring Microsoft Office Access Chapter 2: Relational Databases and Multi-Table Queries

1 SQL Data Types and Schemas

Maintaining Stored Procedures in Database Application

12 Embedding SQL in Programming languages

Using Caché with ODBC

Deploying Oracle Business Intelligence Publisher in J2EE Application Servers Release

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

ORACLE 9I / 10G / 11G / PL/SQL COURSE CONTENT

Instant Chime for IBM Sametime For IBM Websphere and IBM DB2 Installation Guide

Developing SQL and PL/SQL with JDeveloper

Chapter 2 Database System Concepts and Architecture

Duration Vendor Audience 5 Days Oracle Developers, Technical Consultants, Database Administrators and System Analysts

TABLE OF CONTENTS...2 INTRODUCTION...3 APPLETS AND APPLICATIONS...3 JAVABEANS...4 EXCEPTION HANDLING...5 JAVA DATABASE CONNECTIVITY (JDBC)...

A Brief Introduction to MySQL

INTRODUCTION: SQL SERVER ACCESS / LOGIN ACCOUNT INFO:

Oracle Database 10g: Program with PL/SQL

Install guide for Websphere 7.0

Oracle Database 11g: Program with PL/SQL

Overview of Web Services API

Oracle Database: SQL and PL/SQL Fundamentals NEW

USING MYWEBSQL FIGURE 1: FIRST AUTHENTICATION LAYER (ENTER YOUR REGULAR SIMMONS USERNAME AND PASSWORD)

Handling Exceptions. Copyright 2006, Oracle. All rights reserved. Oracle Database 10g: PL/SQL Fundamentals 8-1

ITG Software Engineering

Upgrade Guide BES12. Version 12.1

Oracle Database: Program with PL/SQL

HP Vertica Integration with SAP Business Objects: Tips and Techniques. HP Vertica Analytic Database

Database programming made easier Master thesis of Roland Balk

Handling Exceptions. Schedule: Timing Topic 45 minutes Lecture 20 minutes Practice 65 minutes Total

AVALANCHE MC 5.3 AND DATABASE MANAGEMENT SYSTEMS

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff

OBJECTSTUDIO. Database User's Guide P

Chapter 9 Java and SQL. Wang Yang wyang@njnet.edu.cn

Web Development using PHP (WD_PHP) Duration 1.5 months

PUBLIC Installation: SAP Mobile Platform Server for Linux

OpenLDAP Oracle Enterprise Gateway Integration Guide

Statement Level Interface. Call Level Interface. Static SQL. Status. Connections. Transactions. To connect to an SQL database, use a connect statement

FileMaker 12. ODBC and JDBC Guide

SQL and programming languages

CS/CE 2336 Computer Science II

SQL is capable in manipulating relational data SQL is not good for many other tasks

User Pass-Through Authentication in IBM Cognos 8 (SSO to data sources)

Oracle 10g PL/SQL Training

PL/SQL MOCK TEST PL/SQL MOCK TEST I

Package sjdbc. R topics documented: February 20, 2015

Database Programming with PL/SQL: Learning Objectives

Transcription:

CS346: Database Programming http://warwick.ac.uk/cs346 1

Database programming Issue: inclusionofdatabasestatementsinaprogram combination host language (general-purpose programming language, e.g. Java) data sublanguage (database language, e.g. SQL) stand-alone database programming language, e.g. Oracle s PL/SQL (Programming Language/SQL) Mixing is more common: there is often need to provide database access to existing code. New database PL is a good idea for intensive database interactions. Problems: vendor-specificvariations,evolvingstandards 2

Embedded SQL Database commands embedded into the host language C EXEC SQL... ; SQLJ #sql {... } ; Preprocessor extracts database statements for processing by the DBMS. DBMS generates code, which will be called in the original program instead of the database statements. 3

Host/data language integration issues Impedance mismatch attribute types (database) vs data types (PL) mapping needed (binding) different for each PL! query result structure (multiset of rows) vs data structure (variables) looping construct: cursor/iterator variables data extraction: tuple into distinct program variables These problems do not arise for special database PL. 4

Embedded SQL Advantages Query text is part of the source code. SQL syntax can be checked at compile time. Query plan can be created at compile time. Succinct and readable (queries are separated from the rest) Disadvantage Inability to change/create queries at runtime SQLJ: standard adopted by several vendors (IBM, Oracle, Compaq, Informix, ) Generic interaction pattern: connect,query,update,,close 5

SQLJ Default context public static DefaultContext getconnection(string url, String user, String password, Boolean autocommit) throws SQLException ; Error handling via exceptions (SQLException) try {<operation >} catch (<exception >) {<exception handling >} <continuation code> #sql and into clause (variable names preceded with :) 6

Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Towards JDBC Embedded SQL: static,querytextinsidesourcecode,changes require recompilation Dynamic SQL:moreflexibility,queriesconstructedatruntime(prepared), queries passed as argument strings, SQL checks happen at runtime, more difficult to access query results, numbers of attributes may not be known in advance Library of function calls approach (API): JDBCAPI Class.forName("oracle.jdbc.driver.OracleDriver"); Connection Statement ResultSet 7

Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Local setup "jdbc:oracle:thin:@daisy.warwick.ac.uk:1521:daisy" This will work from daisy. SSH authentication is needed otherwise. ssh -L 7100:daisy:1521 csu @daisy.csv.warwick.ac.uk "jdbc:oracle:thin:@localhost:7100:daisy" The username and password required by getconnection are the database login credentials, i.e. ops$csu. The password can be changed using SQLPLUS ALTER USER ops$csu IDENTIFIED BY new_password; 8

Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

SQL/PSM SQL/Persistent Stored Modules Program modules stored by the DBMS at the database server Can be functions or procedures Example of a database programming language based around SQL Includes general-purpose programming constructs in SQL Usefulness When database program is needed by several applications Reduces data transfer and communication cost between client and server Enhances modelling power provided by views (more complexity) 9

Stored code (either SQL or external) for future calls CREATE PROCEDURE <procedure name> (<parameters>) <local declarations> <procedure body> ; CREATE FUNCTION <function name> (<parameters>) RETURNS <return type> <local declarations> <function body> ; CREATE PROCEDURE <procedure name> (<parameters>) LANGUAGE <programming language name> EXTERNAL NAME <file path name> ; CALL <procedure or function name> (<argument list>) ; 10

Additional SQL/PSM constructs IF <condition> THEN <statement list> ELSEIF <condition> THEN <statement list>... ELSEIF <condition> THEN <statement list> ELSE <statement list> END IF ; WHILE <condition> DO <statement list> END WHILE ; REPEAT <statement list> UNTIL <condition> END REPEAT ; FOR <loop name> AS <cursor name> CURSOR FOR <query> DO <statement list> END FOR ; 11

Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley