1 C. Shahabi Application Programming for Relational Databases Cyrus Shahabi Computer Science Department University of Southern California

Slides:



Advertisements
Similar presentations
Copyright  Oracle Corporation, All rights reserved. 2 Java and Databases: An Overview.
Advertisements

Java Database Connectivity (JDBC). 2/24 JDBC (Java DataBase Connectivity) - provides access to relational database systems JDBC is a vendor independent.
Distributed Application Development B. Ramamurthy.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 32 Java Database.
CSE470 Software Engineering Fall Database Access through Java.
JDBC. In This Class We Will Cover: What SQL is What ODBC is What JDBC is JDBC basics Introduction to advanced JDBC topics.
1 Foundations of Software Design Lecture 27: Java Database Programming Marti Hearst Fall 2002.
JDBC Java API for Database Connectivity. Layout of this recitation Introduction to JDBC API JDBC Architecture Understanding the design of JDBC API –Classes.
JDBC / ODBC JDBC is the java API that facilitate interaction of a java application with the DBMS. FIRST APPROACH:
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.
Java Database Connectivity (JDBC). Introduction Database –Collection of data DBMS –Database management system –Storing and organizing data SQL –Relational.
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.
JDBC Java Database Connectivity. What is an RDBMS? Relational database management system. There are other kinds of DBMS. Access is a GUI on a JET RBDMS.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke; edited K. Shomper1 Database Application Development Chapter 6.
CS178 Database Management “JDBC”. What is JDBC ? JDBC stands for “Java DataBase Connectivity” The standard interface for communication between a Java.
Java Database Connectivity Vijayan Sugumaran Department of DIS Oakland University.
© Wang Bin 2004 JDBC ----Java Database Connectivity.
CSE470 Software Engineering Fall Database Access through Java.
Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.
Java Database Connectivity ASE. Java Database Connectivity (JDBC) l JDBC – provides an interface to Relational Data Sources l JDBC library provides the.
Database Programming in Java Corresponds with Chapter 32, 33.
© D. Wong  Indexes  JDBC  JDBC in J2EE (Java 2 Enterprise Edition)
Dr R R DOCSIT, Dr BAMU. Basic Java : Introduction to JDBC 2 Objectives of This Session State what is Java Database Connectivity State different.
Designing and Developing WS B. Ramamurthy. Plans We will examine the resources available for development of JAX-WS based web services. We need an IDE,
CONTROLPANEL Java.sql package This package provides the APIs for accessing and processing data which is stored in the database especially relational.
JDBC. JDBC stands for Java Data Base Connectivity. JDBC is different from ODBC in that – JDBC is written in Java (hence is platform independent, object.
Mainframe (Host) - Communications - User Interface - Business Logic - DBMS - Operating System - Storage (DB Files) Terminal (Display/Keyboard) Terminal.
JDBC – Java DataBase Connectivity. JDBC API Overview JDBC is Java API that allows the Java programmers to access database management system from Java.
JDBC. Preliminaries Database Database Collection of data Collection of data DBMS DBMS Database management system Database management system Stores and.
Accessing Database using JDBC. JDBC Objectives Gain basic knowledge of Java JDBC Become familiar with the basics of interacting with a database using.
COMP201 Java Programming Topic 15: Database Connectivity JDBC Reading: Chapter 4, Volume 2.
WEB/DB1 DATABASE PROGRAMMING 3JDBC by the ASU Scholars.
Java Database Connectivity (JDBC). Topics 1. The Vendor Variation Problem 2. SQL and Versions of JDBC 3. Creating an ODBC Data Source 4. Simple Database.
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.
Session 30 Basics of JDBC. Java Simplified / Session 30 / 2 of 33 Review A Swing menu consists of a menubar, menuitems and menus. Trees are used to depict.
JDBC CHAPTER-2. JDBC - Java Database Connectivity. JDBC from Sun Microsystems provides API or Protocol to interact with different databases. With the.
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.
UNIT III - JDBC JDBC Overview – JDBC implementation – Connection class – Statements - Catching Database Results, handling database Queries. Networking–
DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
Database Access Using JDBC BCIS 3680 Enterprise Programming.
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 Session 14.
JDBC Chapter 1 JDBC Introduction
JDBC - Java Database Connectivity. JDBC provides Java applications with access to most database systems via SQL The architecture and API closely resemble.
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.
1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 8: Applications Programming for Relational Databases Instructor’s.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Java Database Connectivity.
In the Name Of Almighty Allah. Java Application Connection To Mysql Created by Hasibullah (Sahibzada) Kabul Computer Science Faculty Afghanistan.
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.
Database: JDBC Overview
DEPTT. OF COMP. SC & APPLICATIONS
Interacting with Database
JDBC Database Management Database connectivity
Database JDBC Overview CS Programming Languages for Web Applications
Introduction to Programming with Java
Objectives In this lesson, you will learn about:
Interacting with Database
JDBC – ODBC DRIVERS.
Java Database Connectivity
Java API for Database Connectivity
Presentation transcript:

1 C. Shahabi Application Programming for Relational Databases Cyrus Shahabi Computer Science Department University of Southern California

2 C. Shahabi Overview JDBC Package Connecting to databases with JDBC Executing select queries Executing update queries

3 C. Shahabi Overview Role of an application: Update databases, extract info, through:  User interfaces  Non-interactive programs Development tools (Access, Oracle):  For user Interfaces Programming languages (C, C++, Java,… ):  User Interfaces  Non-Interactive programs  More professional

4 C. Shahabi Client server architecture Database client:  Connects to DB to manipulate data:  Software package  Application (incorporates software package) Client software:  Provide general and specific capabilities  Oracle provides different capabilities as Sybase (its own methods, … )

5 C. Shahabi Client server architecture Client-Server architectures:  2 tier  3 tier  Layer 1:  user interface  Layer 2:  Middleware  Layer 3:  DB server Middleware:  Server for client  Client for DB

6 C. Shahabi Client server architecture Example: Web interaction with DB  Layer 1: web browser  Layer 2: web server + cgi program  Layer 3: DB server

7 C. Shahabi Client server architecture Application layer (1):  User interfaces  Other utilities (report generator, …)  Connect to middleware  Can connect to DB too  Can have more than one connection  Can issue SQL, or invoke methods in lower layers. Middleware layer (2):  More reliable than user applications

8 C. Shahabi Database interaction in Access Direct interaction with DB For implementing applications Not professional Developer edition:  Generates stand alone application Access application:  GUI + “Visual Basic for Applications” code

9 C. Shahabi Database interaction in Access Connection to DB through:  Microsoft Jet database engine  Support SQL access  Different file formats  Other Database Connectivity (ODBC)  Support SQL DBs  Requires driver for each DB server Driver allows the program to become a client for DB  Client behaves Independent of DB server

10 C. Shahabi Database interaction in Access Making data source available to ODBC application:  Install ODBC driver manager  Install specific driver for a DB server  Database should be registered for ODBC manager How application works with data source:  Contacts driver manager to request for specific data source  Manager finds appropriate driver for the source

11 C. Shahabi Database interaction in Java Includes:  Java.sql package  Set of classes  Supports JDBC (java database connectivity?) strategy, independent of the DB server  Difference between JDBC and ODBC:  JDBC driver manager is part of the application

12 C. Shahabi Database interaction in Embedded SQL Extension of a language (C++,C) with new commands:  Void addEmployee( char *ssn, char *lastname,  char *firstname) { Exec SQL –Insert into customer( ssn, lastname, firstname ) values( :ssn, :lastname, :firstname ) }  Not legal language  Compilation precedes by a translation preprocessor from embedded SQL into legal C  Advantages: ???  Disadvantages:  Not portable between database systems  Difficult debugging

13 C. Shahabi JDBC: Architecture Four Architectural Components:  Application (initiates and terminates connections, submits SQL statements)  Driver manager (load JDBC driver)  Driver (connects to data source, transmits requests and returns/translates results and error codes)  Data source (processes SQL statements)

14 C. Shahabi JDBC Architecture (Contd.) Four types of drivers: Bridge:  Translates SQL commands into non-native API. Example: JDBC-ODBC bridge. Code for ODBC and JDBC driver needs to be available on each client. Direct translation to native API, non-Java driver:  Translates SQL commands to native API of data source. Need OS-specific binary on each client. Network bridge:  Send commands over the network to a middleware server that talks to the data source. Needs only small JDBC driver at each client. Direction translation to native API via Java driver:  Converts JDBC calls directly to network protocol used by DBMS. Needs DBMS-specific Java driver at each client.

15 C. Shahabi JDBC package Collection of interfaces and classes:  DriverManager: Loads the driver  Driver: creates a connection  Connection: represents a collection  DatabaseMetaData: information about the DB server  Statement: executing queries  PreparedStatement: precompiled and stored query  CallableStatment: execute SQL stored procedures  ResultSet: results of execution of queries  ResultSetMetaData: meta data for ResultSet Reminder: Each JDBC package implements the interfaces for specific DB server

16 C. Shahabi JDBC, different strategies Strategies to USE JDBC  JDBC-ODBC bridge  Con: ODBC must be installed  JDBC database client  Con: JDBC driver for each server must be available  JDBC middleware client  Pro: Only one JDBC driver is required  Application does not need direct connection to DB (e.g., applet)

17 C. Shahabi Connecting with JDBC Database connection needs two pieces  JDBC package driver class name  Package driver provide connection to DB  URL of the database  JDBC package designator  Location of the server  Database designator, in form of: Server name, Database name, Username, password, … Properties

18 C. Shahabi Connecting to DB with JDBC Step 1: Find, open and load appropriate driver  1. Class.forName( “sun.jdbc.odbc.JdbcOdbcDriver” );  2. Class.forName( “oracle.thin.Driver” );  3. Class.forName( “symantec.dbAnywhere.driver” ); Or:  4. DriverManager.registerDriver( your jdbc driver );  Informs availability of the driver to “DriverManager” (registers the driver with DriverManager)  (Example 1)

19 C. Shahabi Connecting to DB with JDBC Step 2: Make connection to the DB  Connection conn = DriverManager( URL, Properties); Properties: specific to the driver  URL = Protocol + user Protocol= jdbc: : –E.g.: jdbc:odbc:mydatabase –E.g.: jdbc:oracle:thin://oracle.cs.fsu.edu/bighit  (Example 1)

20 C. Shahabi Connecting to DB with JDBC Step 3: Make Statement object  Used to send SQL to DB  executeQuery(): SQL that returns table  executeUpdate(): SQL that doesn’t return table  Execute(): SQL that may return both, or different thing Step 4: obtain metadata (optional)  DatabaseMetaData object getTimeDatefunctions: all date and time functions ….  (Example 2)

21 C. Shahabi Executing select queries Step 5: issue select queries  Queries that return table as result  Using statement object  Uses executeQuery() method  Return the results as ResultSet object  Meta data in ResultSetMetaData object  Every call to executeQuery() deletes previous results  (Example 2)

22 C. Shahabi Executing select queries Step 6: retrieve the results of select queries  Using ResultSet object  Returns results as a set of rows  Accesses values by column name or column number  Uses a cursor to move between the results  Supported methods: JDBC 1: scroll forward JDBC 2: scroll forward/backward, absolute/relative positioning, updating results. JDBC 2: supports SQL99 data types(blob, clob,…)  Meta data in ResultSetMetaData:  Number of columns, Column names, column type name,  (Example 2)

23 C. Shahabi Matching Java and SQL Data Types getTimestamp()java.sql.TimeStampTIMESTAMP getTime()java.sql.TimeTIME getDate()java.sql.DateDATE getFloat()DoubleREAL getInt()IntegerINTEGER getDouble()DoubleFLOAT getDouble()DoubleDOUBLE getString()StringVARCHAR getString()StringCHAR getBoolean()BooleanBIT ResultSet get methodJava classSQL Type

24 C. Shahabi Executing update queries Step 7: issue update queries  Queries that return a row count (integer) as result  Number of rows affected by the query  -1 if error  Using statement object  Uses executeUpdate() method  Meta data in ResultSetMetaData object  (Example 3)

25 C. Shahabi Executing update queries Step 8: More Advanced  Use PreparedStatement  faster than regular Statement  (Example 4)  Cursors  forward, backward, absolute/relative positions  (Example 5)

26 C. Shahabi Mapping Objects To read attributes that are retrieved as objects:  Example: Spatial data types  (Example 6: it is for point, line and other types are similar)  Read “Oracle Spatial – User’s Guide and Reference” Chapter 2 for geometry types Chapter 9-14 for geometry functions  Read “Oracle Spatial API Document” for reading geometry types in Java