Embedded SQL Host Language (record-oriented) DBMS (set-oriented) 1. Query 3. Process a tuple at a time 4. Close Cursor 2. Evaluate query. Provide cursor.

Slides:



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

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.
15-Jun-15 JDBC. JDBC is a Sun trademark It is often taken to stand for Java Database Connectivity Java is very standardized, but there are many versions.
1 C. Shahabi Application Programming for Relational Databases Cyrus Shahabi Computer Science Department University of Southern California
Java Database Connectivity (JDBC) java.sql package to query and update the database. JDBC is an API that allows java to communicate with a database server.
1 Lecture 29 More on JDBC Overview  Objectives of this lecture  JDBC and its Drivers  Connecting to Databases (Java’s Connection class)  Querying a.
Client-server database systems and ODBC l Client-server architecture and components l More on reliability and security l ODBC standard.
Session-01. Hibernate Framework ? Why we use Hibernate ?
Database Connectivity ODBC, JDBC and SQLJ CS2312.
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
CSCI 6962: Server-side Design and Programming
Database System Concepts and Architecture Lecture # 3 22 June 2012 National University of Computer and Emerging Sciences.
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.
Beginning Databases with JDBC Mike Bradley Adapted from and notes by Kevin Parker, Ph.D.
Announcements Read JDBC Project Step 5, due Monday.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 9- 1 DATADABASE PROGRAMMING 2Chapter 13 from our text.
© D. Wong  Indexes  JDBC  JDBC in J2EE (Java 2 Enterprise Edition)
Database Environment Chapter 2 AIT632 Sungchul Hong.
CHAPTER 14 USING RELATIONAL DATABASES TO PROVIDE OBJECT PERSISTENCE (ONLINE) © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database.
Midterm Exam Chapters 1,2,3,5, 6,7 (closed book) March 11, 2014.
M1G Introduction to Database Development 6. Building Applications.
MySQL, Java, and JDBC CSE 3330 Southern Methodist University.
12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming.
CS 405G: Introduction to Database Systems Database programming.
Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.
Stored procedures1 Stored procedures and functions Procedures and functions stored in the database.
Introduction to the new mainframe © Copyright IBM Corp., All rights reserved. Chapter 12 Understanding database managers on z/OS.
Advanced SQL: Cursors & Stored Procedures
© 2011 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 14 Using Relational Databases to Provide Object Persistence (Overview) Modern Database.
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  Oracle Corporation, All rights reserved. 7 Accessing a Database Using SQLJ.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Java Database Connectivity. Java and the database Database is used to store data. It is also known as persistent storage as the data is stored and can.
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.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Application Development Chapter 6 Sections –
Java and Databases. JDBC Architecture Java Application JDBC API Data Base Drivers AccessSQL Server DB2InformixMySQLSybase.
DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
JDBC and SQLJ CIS 612 Spring JDBC JDBC is an API that enables database access from Java programs JDBC for DB access provides ◦ Portability across.
1 Database Application Development Chapter 6 Sections –
JDBC CS 260 Database Systems. Overview  Introduction  JDBC driver types  Eclipse project setup  Programming with JDBC  Prepared statements  SQL.
Access Databases from Java Programs via JDBC Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale
SCU Fall 2002JoAnne Holliday10–1 Schedule Today u Triggers, Procedures, PL/SQL. u Read Sections , 8.1, 8.5. Next u Transaction concepts, security.
Ch. NoNameMarks 01AWT24 02Networking18 03JDBC20 04Swing18 05Servlet20 Advance Java Programming.
Introduction to JDBC Instructor: Mohamed Eltabakh 1.
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
CS422 Principles of Database Systems Object-Relational Mapping (ORM) Chengyu Sun California State University, Los Angeles.
CS520 Web Programming Object-Relational Mapping with Hibernate and JPA (I) Chengyu Sun California State University, Los Angeles.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
CS422 Principles of Database Systems JDBC and Embedded SQL Chengyu Sun California State University, Los Angeles.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Application Development Chapter 6.
DEPTT. OF COMP. SC & APPLICATIONS
CS3220 Web and Internet Programming Database Access with JDBC
JDBC 15-Apr-18.
Web Technologies IT230 Dr Mohamed Habib.
Advanced Web Automation Using Selenium
JDBC 21-Aug-18.
Prof: Dr. Shu-Ching Chen TA: Sheng Guan
Client Access, Queries, Stored Procedures, JDBC
JDBC 15-Nov-18.
Database Application Development
DB Programming: SQL Programming Techniques
CMPT 354: Database System I
CS3220 Web and Internet Programming Database Access with JDBC
CS3220 Web and Internet Programming Database Access with JDBC
Presentation transcript:

Embedded SQL Host Language (record-oriented) DBMS (set-oriented) 1. Query 3. Process a tuple at a time 4. Close Cursor 2. Evaluate query. Provide cursor to query result. 1

JDBC  Java DataBase Connectivity  Standard to access databases using Java  Approach:  Create a connection to the database  Create a statement to be executed by the database  Set parameters of the statement (optional)  Execute the statement; return ResultSet (aka cursor)  Read tuples from ResultSet  JDBC is not restricted to SQL! 2

Create Connection to the DB Connection conn = DriverManager.getConnection( urlDB, username, password) Need JDBC driver (provided by DBMS) urlDB: Identifies the database uniquely N.B. one server could provide multiple DBs. Username, Password: as usual Other settings provided by configuration e.g., buffer pool, app heap, TA level,... 3

Output the names of all Profs Statement s = conn.createStatement(); ResultSet r; s.execute(„SELECT name FROM professor“); r = s.getResultSet(); while (r.next()) { output(r.getString(1)); } r.close(); 4

Parameterized Queries PreparedStatement s = conn.prepareStatement( „SELECT name FROM prof WHERE level = ?“); ResultSet r;... s.setString(1, „AP“); r = s.executeQuery(); while (r.next())... 5

Tipps and Tricks Connection Pooling  Create several connections to the database  Grab an unused connection before accessing DB  Execute statement using that connection  Why? Do not block the database with heavy queries  Rule of thumb: 5 – 10 connections  (too many connections will hurt performance and avail.) 6

Tipps and Tricks Cursor Caching  Use PreparedStatements!  Example: insert into professor(name, level) values(?,?)  Why? Avoid overhead (optimizer) for every call  Disadvantage? Optimizer has no statistics 7

JDBC Summary  Simple protocol to send messages to the database  Database is typically deployed as a server!  SQL Syntax not checked at compile time!!!  For Java, those are just strings  (Type) Safety of parameters checked at running time  All JDBC Statements raise SQLExceptions  Should be caught!  New Standard: SQLJ 8

SQL J  SQL embedded in Java  Use preprocessor at compile time for type safety, SQL syntax  Annotate SQL statements with #sql  Iterator (Cursor) similar to JDBC #sql iterator ProfIterator(String name, String level); ProfIterator myProfs; #sql myProfs = { SELECT name, level FROM Professor }; while (myProfs.next()) { System.out.println(myProfs.name() + myProfs.level()); } 9

Object-Relational Mapping (e.g., Hibernate)  With JDBC and SQL-J, programmers wear two hats  Object-oriented programming with Java  Database programming with SQL  Two languages, two data models, two type systems,...  Duplicate work for logging, caching, error handling, security 10

Java/C#  SQL  Java/C# Traditional Multi-tier Architecture 11 Outgoing message (XML/JSON) REST communication XML  Java/C#  XML Java/C#, JavaScript application logic SQL database (queries, updates) Incoming message (XML/JSON) security, caching, consistency,... security, caching, consistency,... security, caching, consistency,... Problem: Every layer reinvents the wheel!!! security, caching, consistency, error handling, data model,... huge overheads during development (technology jungle) huge overheads during deployment (configuration) huge overheads during operation (RPCs, duplicate work)

Object-Relational Mapping (e.g., Hibernate)  With JDBC and SQL-J, programmers wear two hats  Object-oriented programming with Java  Database programming with SQL  Two languages, two data models, two type systems,...  Duplicate work for logging, caching, error handling, security  Idea: Automate the database programming  DDL: generate „create table“ from XML, annotations  Queries: generate „select“ from getters and setters  Make everything look like Java  Idea applicable to relational and XML!  Please, do not use in project! We learn the bare bones here!!! 12

13 XML Mapping to generic structures ….. ….. … …. ….. Class DomNode{ public String getNodeName(); public String getNodeValue(); public void setNodeValue(nodeValue); public short getNodeType(); } Mappings

14 Mapping to non-generic structures ….. ….. … …. ….. Class PurchaseOrder { public List getLineItems(); …….. } Mappings Class Book { public List getAuthor(); public String getTitle(); …… }

Other Approaches  New programming languages  e.g., Ruby, XQuery, etc.  integrate app scripting and database programming  address additional impedance mismatch with Web  PL/SQL (stored procedures)  bring application logic to database: „;“, „while“, blocks,...  rather than database logic to application  huge performance advantages  LINQ (language integrated queries)  provide a super-data model at application layer  (mother of all Hibernates) 15