SQL and programming languages



Similar documents
Database Access from a Programming Language: Database Access from a Programming Language

Database Access from a Programming Language:

Embedded SQL. Unit 5.1. Dr Gordon Russell, Napier University

The JAVA Way: JDBC and SQLJ

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

SQL and Java. Database Systems Lecture 19 Natasha Alechina

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

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

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

SQL: Programming. Introduction to Databases CompSci 316 Fall 2014

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

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

Database System Concepts

Programming Database lectures for mathema

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

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

Java DB Performance. Olav Sandstå Sun Microsystems, Trondheim, Norway Submission ID: 860

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

CS/CE 2336 Computer Science II

CS346: Database Programming.

Writing MySQL Scripts With Python's DB-API Interface

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

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

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

Introduction Web Portal Main Page Group Management Create group Modify Group Member List... 5

Microsoft SQL Server Features that can be used with the IBM i

dbext for Vim David Fishburn h5p://

Accesssing External Databases From ILE RPG (with help from Java)

LSINF1124 Projet de programmation

UQC103S1 UFCE Systems Development. uqc103s/ufce PHP-mySQL 1

Database Access via Programming Languages

Package sjdbc. R topics documented: February 20, 2015

FileMaker 11. ODBC and JDBC Guide

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

Embedded SQL programming

SQL Injection. Slides thanks to Prof. Shmatikov at UT Austin

Databases and SQL. The Bioinformatics Lab SS Wiki topic 10. Tikira Temu. 04. June 2013

Introductory Concepts

Real SQL Programming 1

Java and Microsoft Access SQL Tutorial

7 Web Databases. Access to Web Databases: Servlets, Applets. Java Server Pages PHP, PEAR. Languages: Java, PHP, Python,...

Writing Scripts with PHP s PEAR DB Module

CHAPTER 5 INTELLIGENT TECHNIQUES TO PREVENT SQL INJECTION ATTACKS

Java Server Pages and Java Beans

12 Embedding SQL in Programming languages

Setting up a database for multi-user access

Application Development A Cocktail of Java and MCP. MCP Guru Series Dan Meyer & Pramod Nair

public class ResultSetTable implements TabelModel { ResultSet result; ResultSetMetaData metadata; int num cols;

3D VIRTUAL DESKTOP APPLICATION Of UNSW. Introduction. What we propose to do 2/4. What we propose to do 1/4. What we propose to do 4/4

Database Management System Choices. Introduction To Database Systems CSE 373 Spring 2013

1 SQL Data Types and Schemas

Computing with large data sets

12 Embedding SQL in Programming languages

CSC 370 Database Systems Summer 2004 Assignment No. 2

The Data Access Handbook

Supplement IV.D: Tutorial for MS Access. For Introduction to Java Programming By Y. Daniel Liang

FileMaker 13. ODBC and JDBC Guide

SQL injection: Not only AND 1=1. The OWASP Foundation. Bernardo Damele A. G. Penetration Tester Portcullis Computer Security Ltd

14 Triggers / Embedded SQL

1 File Processing Systems

Microsoft SQL Server Features that can be used with the IBM i

2015, André Melancia (Andy.PT) 1

CS2506 Operating Systems II Lab 8, 8 th Tue/03 /2011 Java API

Java Programming. JDBC Spring Framework Web Services

TECH TUTORIAL: EMBEDDING ANALYTICS INTO A DATABASE USING SOURCEPRO AND JMSL

JDBC. It is connected by the Native Module of dependent form of h/w like.dll or.so. ex) OCI driver for local connection to Oracle

Writing MySQL Scripts with Python DB-API

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

SQLITE C/C++ TUTORIAL

High-Performance Oracle: Proven Methods for Achieving Optimum Performance and Availability

Security Module: SQL Injection

Abstract. Introduction. Web Technology and Thin Clients. What s New in Java Version 1.1

SQL Basics for RPG Developers

Database Driven Websites Using PHP with Informix

ERserver. DB2 Universal Database for iseries SQL Programming with Host Languages. iseries. Version 5

Connect to MySQL or Microsoft SQL Server using R

Hive Interview Questions

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

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

Programming Flaws and How to Fix Them

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

Oracle to MySQL Migration

Getting Started using the SQuirreL SQL Client

Part 2 - The Database Environment

Intro to Embedded SQL Programming for ILE RPG Developers

Accessing Your Database with JMP 10 JMP Discovery Conference 2012 Brian Corcoran SAS Institute

Week 1 Part 1: An Introduction to Database Systems. Databases and DBMSs. Why Use a DBMS? Why Study Databases??

How To Let A Lecturer Know If Someone Is At A Lecture Or If They Are At A Guesthouse

Application note: Connecting the to a Database

FileMaker 12. ODBC and JDBC Guide

More SQL: Assertions, Views, and Programming Techniques

FileMaker 14. ODBC and JDBC Guide

Java MySQL Connector & Connection Pool

An Oracle White Paper June Migrating Applications and Databases with Oracle Database 12c

Chapter 2 Database System Concepts and Architecture

Transcription:

SQL and programming languages SET08104 Database Systems Copyright Napier University Slide 1/14

Pure SQL Pure SQL: Queries typed at an SQL prompt. SQL is a non-procedural language. SQL specifies WHAT, not HOW. Pure SQL is good for: defining database structure generating low-volume, ad hoc queries prototyping Sophisticated applications are often implemented by using SQL in combination with a programming language. Slide 2/14

Embedded SQL SQL can be embedded within procedural programming languages. These languages include C/C++, Java, Perl, Python, and PHP. Embedded SQL supports: Highly customised applications. Background applications running without user intervention. Combining database tools with programming tools. Databases on the WWW. Slide 3/14

Two types of embedding Low-level embedding (eg. C/C++): SQL and program compiled into a single executable. Very efficient link. ODBC - Open Database Connectivity (eg. PHP/Java): SQL query sent from the program to the database as a string. Results returned as an array or list. Independence of program and database: Each language has one DBI (database interface) for all DBMS types. (For example, JDBC for Java.) Separate database drivers (DBD) for each DBMS type. Slide 4/14

Low-level embedding (eg. C/C++) Queries consist of a mixture of SQL and special commands. A cursor steps through the resulting rows one at a time. For example: EXEC SQL SELECT empname INTO :ename FROM employee WHERE eno = :eno; Slide 5/14

Cursors A pointer to the current item in a query result set. Starts with the first item. Steps through the results one at a time. Some cursor implementations allow to step back up as well. Slide 6/14

ODBC database connections Connect to the database. Prepare a query (as a string). Execute the query. Fetch the results (as an array of rows). Finish the query (so that DB can clean up its buffers). Disconnect from the database. Slide 7/14

For example: Java import the DBI libraries Class.forName( oracle.jdbc.oracledriver ) connect to the database Connection con = DriverManager.getConnection ( jdbc:oracle:databasename, mylogin, mypassword ); Execute a query ResultSet rs = stmt.executequery ( SELECT empno, surname FROM employee ); Cursor points to the first row rs.next() Slide 8/14

Fetching the result (Java) while (rs.next()) { int emp = rs.getint("empno"); String surn = rs.getstring("surname"); System.out.println(emp + " " + surn); } or while (rs.next()) { int emp = rs.getint(1); String surn = rs.getstring(2); System.out.println(emp + " " + surn);} Slide 9/14

For example: PHP connect to the database $link = mysql connect( hostname, uname, passwd ); Select database mysql select db( test ); Execute a query $result = mysql query( select * from test ); Fetch the result (See next slide) Finish the query mysql free result($result); Disconnect the database mysql close($link); mysql commands might throw errors, which should be caught:... or die( Error message. mysql error()); Slide 10/14

Fetching the result (PHP) echo "<table>"; while ($line = mysql fetch array($result, MYSQL ASSOC)){ echo "<tr>"; echo "<td>",$line[ firstfield ],"</td>"; echo "<td>",$line[ secondfield ],"</td>"; echo "<td>",$line[ thirdfield ],"</td>"; echo "</tr>"; } echo "</table>"; Slide 11/14

Security Warning! Using MySQL and PHP on the web is a potential severe security risk. There is a lot of nonsense information about how to use MySQL with PHP on the web. It is especially dangerous to take any user input (i.e. form variables) and use them directly in an SQL query. For an experienced programmer, PHP provides a lot of support for writing secure code (but that is beyond this lecture). Inexperienced programmers should not use MySQL with PHP. Slide 12/14

Security Warning continued This is a statement found in a PHP forum: At first my remote connection to Mysql did not work, but then I discovered I only had to stop my firewall and it worked fine. Slide 13/14

Security Warning continued This is what a hacker might type into a textfield written by the user on the previous slide: 0; SELECT * from mysql.user; - - Slide 14/14