CS 405G: Introduction to Database Systems Database programming.

Slides:



Advertisements
Similar presentations
Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Advertisements

Copyright  Oracle Corporation, All rights reserved. 2 Java and Databases: An Overview.
Java Database Connectivity (JDBC). 2/24 JDBC (Java DataBase Connectivity) - provides access to relational database systems JDBC is a vendor independent.
Database programming in Java An introduction to Java Database Connectivity (JDBC)
1 Lecture 05: Database Programming (JDBC). 2 Outline JDBC overview JDBC API Reading: Chapter 10.5 PostgreSQL JDBC interface documentation
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Introduction to SQL Programming Techniques.
1 Lecture 05: Database Programming (JDBC). 2 Outline JDBC overview JDBC API Reading: Chapter 10.5 Pointbase Developer Manual.
1 C. Shahabi Application Programming for Relational Databases Cyrus Shahabi Computer Science Department University of Southern California
1 Lecture 29 More on JDBC Overview  Objectives of this lecture  JDBC and its Drivers  Connecting to Databases (Java’s Connection class)  Querying a.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Overview of Database Languages and Architectures.
Centralized and Client/Server Architecture and Classification of DBMS
Dale Roberts 8/24/ Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
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 Java Database Connection (JDBC) There are many industrial-strength DBMS's commercially available in the market. Oracle, DB2, and Sybase are just a few.
Overview of JDBC and Pro*C 1 Overview of JDBC,Pro*C and Oracle connectivity on Omega CSE 5330 – Database Systems.
Database Management Systems 1 Oracle Programming.
© Wang Bin 2004 JDBC ----Java Database Connectivity.
CSE470 Software Engineering Fall Database Access through Java.
Beginning Databases with JDBC Mike Bradley Adapted from and notes by Kevin Parker, Ph.D.
MySQL, Java, and JDBC CSE 3330 Southern Methodist University.
JDBC Tutorial MIE456 - Information Systems Infrastructure II Vinod Muthusamy November 4, 2004.
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui COMP 302 Database Systems Java Data Base Connectivity Lecturer Dr Pavle Mogin.
Overview of JDBC and Pro*C 1 CSE 5330 – Database Systems.
Accessing Database using JDBC. JDBC Objectives Gain basic knowledge of Java JDBC Become familiar with the basics of interacting with a database using.
WEB/DB1 DATABASE PROGRAMMING 3JDBC by the ASU Scholars.
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.
Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 2-1 Data Models Data Model: A set.
Copyright © 2002 ProsoftTraining. All rights reserved. Building Database Client Applications Using JDBC 2.0.
JDBC Database Programming in Java Prepared by., Mrs.S.Amudha AP/SWE.
JDBC. Java.sql.package The java.sql package contains various interfaces and classes used by the JDBC API. This collection of interfaces and classes enable.
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 –
12/6/2015B.Ramamurthy1 Java Database Connectivity B.Ramamurthy.
Java and Databases. JDBC Architecture Java Application JDBC API Data Base Drivers AccessSQL Server DB2InformixMySQLSybase.
COMP 321 Week 4. Overview Normalization Entity-Relationship Diagrams SQL JDBC/JDBC Drivers hsqldb Lab 4-1 Introduction.
Java JDBC API. A Java API To Access almost any kind of tabular data To Access almost any kind of tabular data Trademarked (not an acronym) Trademarked.
1 Database Application Development Chapter 6 Sections –
Database Access Using JDBC BCIS 3680 Enterprise Programming.
JDBC CS 260 Database Systems. Overview  Introduction  JDBC driver types  Eclipse project setup  Programming with JDBC  Prepared statements  SQL.
CSI 3125, Preliminaries, page 1 JDBC. CSI 3125, Preliminaries, page 2 JDBC JDBC stands for Java Database Connectivity, which is a standard Java API (application.
Access Databases from Java Programs via JDBC Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale
Basics of JDBC.
Basics of JDBC Session 14.
JDBC (Java Database Connectivity)
Ch. NoNameMarks 01AWT24 02Networking18 03JDBC20 04Swing18 05Servlet20 Advance Java Programming.
Database Programming With Java & JDBC Reading: DD Ch. 18, pp al/jdbc/index.html, or anything covering JDBC.
2) Database System Concepts and Architecture. Slide 2- 2 Outline Data Models and Their Categories Schemas, Instances, and States Three-Schema Architecture.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Java Database Connectivity.
1 JDBC – Java Database Connectivity CS , Spring 2010.
Intro to JDBC Joseph Sant Applied Computing and Engineering Sciences Sheridan ITAL.
6-1 JAVA DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
Java and database. 3 Relational Databases A relational Database consists of a set of simple rectangular tables or relations The column headings are.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
JDBC.
CS320 Web and Internet Programming Database Access with JDBC Chengyu Sun California State University, Los Angeles.
Instructor: Jinze Liu Fall /8/2016Jinze University of Kentucky 2 Database Project Database Architecture Database programming.
JDBC – Java DataBase Connectivity
Lec - 14.
CS 505: Intermediate Topics to Database Systems
Course Outcomes of Advanced Java Programming AJP (17625, C603)
Database JDBC Overview CS Programming Languages for Web Applications
Prof: Dr. Shu-Ching Chen TA: Sheng Guan
JDBC – Java DataBase Connectivity
JDBC – Java DataBase Connectivity
Mr. Harish Sharma Asst. Professor Dept. of CA & IT SGRRITS Dehradun
Interacting with Database
JDBC – Java DataBase Connectivity
Presentation transcript:

CS 405G: Introduction to Database Systems Database programming

10/12/2015Jinze University of Kentucky2 Today’s Topic Database Architecture Database programming

10/12/2015Jinze University of Kentucky3 Centralized Architectures Centralized DBMS: combines everything into single system including- DBMS software, hardware, application programs and user interface processing software.

10/12/2015Jinze University of Kentucky4 Two Tier Client-Server Architectures Server: provides database query and transaction services to client machines Client: provide appropriate interfaces to server. Run User Interface (UI) Programs and Application Programs Connect to servers via network.

10/12/2015Jinze University of Kentucky5 Client-Server Interface The interface between a server and a client is commonly specified by ODBC (Open Database Connectivity) Provides an Application program interface (API) Allow client side programs to call the DBMS.

10/12/2015Jinze University of Kentucky6 Three (n) Tier Client-Server Architecture WAN Clients Web server Application servers Database servers The intermediate layer is called Application Server or Web Server, or both: Stores the web connectivity software and business logic for applications Acts like a conduit for sending partially processed data between the database server and the client. Additional Features Security: encrypt the data at the server and client before transmission Intermediate layer

10/12/2015Jinze University of Kentucky7 Database Programming: Overview Pros and cons of SQL Very high-level, possible to optimize Specifically designed for databases and is called data sublanguage Not intended for general-purpose computation, which is usually done by a host language Solutions Augment SQL with constructs from general-purpose programming languages (SQL/PSM) Use SQL together with general-purpose programming languages Database APIs, embedded SQL, JDBC, etc.

10/12/2015Jinze University of Kentucky8 Clarification of Terms (cont.) John went to his office. He has a JAVA program, which connects to a SqlServer database in his company’s intranet. He use the program to retrieve data and print out reports for his business partner. Client-server model Use APIs provided by SqlServer to access the database Java supports SqlServer API using JDBC

10/12/2015Jinze University of Kentucky9 Clarification of Terms (cont.) After job, John went to youtube.com, searched for a video of Thomas train for his children, and downloaded one Client-mediate level-sever model “SQL experience a plus” from a job ad linked from youtube’s web site. WAN

10/12/2015Jinze University of Kentucky10 Impedance mismatch and a solution SQL operates on a set of records at a time Typical low-level general-purpose programming languages operates on one record at a time  Solution: cursor Open (a result table): position the cursor before the first row Get next: move the cursor to the next row and return that row; raise a flag if there is no such row Close: clean up and release DBMS resources  Found in virtually every database language/API With slightly different syntaxes

10/12/2015Jinze University of Kentucky11 A Typical Flow of Interactions A client (user interface, web server, application server) opens a connection to a database server A client interact with the database server to perform query, update, or other operations. A client terminate the connection

10/12/2015Jinze University of Kentucky12 Interfacing SQL with another language API approach SQL commands are sent to the DBMS at runtime Examples: JDBC, ODBC (for C/C++/VB), Perl DBI These API’s are all based on the SQL/CLI (Call-Level Interface) standard Embedded SQL approach SQL commands are embedded in application code A precompiler checks these commands at compile-time and converts them into DBMS-specific API calls Examples: embedded SQL for C/C++, SQLJ (for Java)

10/12/2015Jinze University of Kentucky13 Example API: JDBC JDBC (Java DataBase Connectivity) is an API that allows a Java program to access databases // Use the JDBC package: import java.sql.*; … public class … { … static { // Load the JDBC driver: try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { … } } … }

10/12/2015Jinze University of Kentucky14 Connections // Connection URL is a DBMS-specific string: String url = ” ”; // Making a connection: conn =DriverManager.getConnection(url,username,password) … // Closing a connection: con.close(); For clarity we are ignoring exception handling for now

10/12/2015Jinze University of Kentucky15 Statements // Create an object for sending SQL statements: Statement stmt = con.createStatement(); // Execute a query and get its results: ResultSet rs = stmt.executeQuery(”SELECT name, passwd FROM regiusers”); // Work on the results: … // Execute a modification (returns the number of rows affected): int rowsUpdated = stmt.executeUpdate (”UPDATE regiusers SET passwd = ’1234’ WHERE name = ‘sjohn’ ”); // Close the statement: stmt.close();

10/12/2015Jinze University of Kentucky16 Query results // Execute a query and get its results: ResultSet rs = stmt.executeQuery(”SELECT name, passwd FROM regiusers”); // Loop through all result rows: while (rs.next()) { // Get column values: String name = rs.string(1); String passwd = rs.getString(2); // Work on sid and name: … } // Close the ResultSet : rs.close();

10/12/2015Jinze University of Kentucky17 Other ResultSet features Move the cursor (pointing to the current row) backwards and forwards, or position it anywhere within the ResultSet Update/delete the database row corresponding to the current result row Analogous to the view update problem Insert a row into the database Analogous to the view update problem

10/12/2015Jinze University of Kentucky18 Prepared statements: motivation Statement stmt = con.createStatement(); for (int age=0; age = ” + age + ” AND age < ” + (age+10)); // Work on the results: … } Every time an SQL string is sent to the DBMS, the DBMS must perform parsing, semantic analysis, optimization, compilation, and then finally execution These costs are incurred 10 times in the above example A typical application issues many queries with a small number of patterns (with different parameter values)

10/12/2015Jinze University of Kentucky19 Transaction processing Set isolation level for the current transaction con.setTransactionIsolationLevel( l ); Where l is one of TRANSACTION_SERIALIZABLE (default), TRANSACTION_REPEATABLE_READ, TRANSACTION_READ_COMITTED, and TRANSACTION_READ_UNCOMMITTED Set the transaction to be read-only or read/write (default) con.setReadOnly(true | false); Turn on/off AUTOCOMMIT (commits every single statement) con.setAutoCommit(true | false); Commit/rollback the current transaction (when AUTOCOMMIT is off) con.commit(); con.rollback();

10/12/2015Jinze University of Kentucky20 Pros and cons of embedded SQL Pros More compile-time checking (syntax, type, schema, …) Code could be more efficient (if the embedded SQL statements do not need to checked and recompiled at run- time) Cons DBMS-specific Vendors have different precompilers which translate code into different native API’s Application executable is not portable (although code is) Application cannot talk to different DBMS at the same time

10/12/2015Jinze University of Kentucky21 Summary Two-tier architecture Three-tier architecture SQL C, C++, JAVA, PERL Database programming Client-server Client, mediate level, server Web server, application server Data sublanguage Host language API Embedded SQL