Basics of JDBC Session 14.

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.
JDBC - Java Database Connectivity The objectives of this chapter are: To describe the architecture of JDBC To outline the classes in the java.sql package.
Java and Databases CS-328 Dick Steflik. Database Drivers Think of a database as just another device connected to your computer like other devices it has.
Distributed Application Development B. Ramamurthy.
SQL (Structured Query Language) X/OPEN Call Level Interface For SQL ODBC (Open DataBase Connectivity) API JDBC (Java DataBase Connectivity) API SQL (Structured.
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.
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:
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.
JDBC Vs. Java Blend Presentation by Gopal Manchikanti Shivakumar Balasubramanyam.
Java Database Connectivity (JDBC) Francisco Pajaro Saul Acosta Nahum Quezada Manuel Rubio.
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.
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.
Dr R R DOCSIT, Dr BAMU. Basic Java : Introduction to JDBC 2 Objectives of This Session State what is Java Database Connectivity State different.
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
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,
Connecting to Oracle using Java November 4, 2009 David Goldschmidt, Ph.D. David Goldschmidt, Ph.D.
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.
JDBC. Preliminaries Database Database Collection of data Collection of data DBMS DBMS Database management system Database management system Stores and.
JDBC Enterprise Systems Programming. JDBC  Java Database Connectivity  Database Access Interface provides access to a relational database (by allowing.
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.
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.
JDBC CS 124. JDBC Java Database Connectivity Database Access Interface provides access to a relational database (by allowing SQL statements to be sent.
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–
1 Session 2 Module 3: Scrollable Resultset and Rowsets.
DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
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
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.
Advanced Java Session 5 New York University School of Continuing and Professional Studies.
Ch. NoNameMarks 01AWT24 02Networking18 03JDBC20 04Swing18 05Servlet20 Advance Java Programming.
© 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.
Java and database. 3 Relational Databases A relational Database consists of a set of simple rectangular tables or relations The column headings are.
R EMAINING TOPICS IN JDBC Sagun Dhakhwa. O VERVIEW Introduction to JDBC API Types of JDBC Drivers Introduction to ODBC.
DEPTT. OF COMP. SC & APPLICATIONS
Note: To complete the examples in this section you need access to a database!! Most of the examples work for any database with JDBC drivers. However, connecting.
Interacting with Database
JDBC Database Management Database connectivity
Introduction to Programming with Java
Mr. Harish Sharma Asst. Professor Dept. of CA & IT SGRRITS Dehradun
Interacting with Database
JDBC – ODBC DRIVERS.
Java Database Connectivity
ODBC and JDBC.
Java API for Database Connectivity
Presentation transcript:

Basics of JDBC Session 14

Objectives Explain the concept of database connectivity Describe ODBC Discuss what is JDBC Discuss why we need JDBC Describe the java.sql package in brief Discuss types of drivers Explain the anatomy of a JDBC program Basics of JDBC / 2 of 23

Database A database contains data that is in an organized form Client/Server applications make extensive use of database programming Activities may involve opening a connection, communicating with a database, executing SQL statements and retrieving query results Standardized APIs are available that simplify database programming. Examples of these are ODBC and JDBC Basics of JDBC / 3 of 23

ODBC Open DataBase Connectivity (ODBC) is an Application Programming Interface (API) provided by Microsoft for accessing databases Provides functions to insert, modify and delete data and obtain information from the database Basics of JDBC / 4 of 23

How ODBC connection takes place? Access Driver Access Database Oracle Database Application ODBC Interface Driver Manager Oracle Driver … … Application could be a GUI program Makes use of ODBC to interact with databases Driver Manager is part of Microsoft ODBC and is used to manage various drivers in the system Basics of JDBC / 5 of 23

Need for JDBC ODBC uses a C interface that has lot of drawbacks A literal translation of the ODBC C interface into a Java API would not be desirable ODBC mixes simple and advanced features together and has complex options even for simple queries A Java API like JDBC is needed in order to enable a “pure Java” solution JDBC is portable JDBC is a standard interface for Java programmers to access relational databases Basics of JDBC / 6 of 23

JDBC JDBC is a Java Database Connectivity API that is a part of the Java Enterprise API Defines a set of API objects and methods to interact with databases JDBC is a must for all Java applications that access data stored in external data providers like SQL Server, Oracle or Access Basics of JDBC / 7 of 23

JDBC Driver Types (1) JDBC-ODBC Bridge plus ODBC Driver ODBC is not readily convertible to Java Sun provides a bridge driver to access ODBC data sources from JDBC This is called the JDBC-ODBC Bridge plus ODBC driver Database Server Oracle ODBC Driver JDBC - ODBC bridge Database Server SQL Server ODBC Driver DB-client Basics of JDBC / 8 of 23

JDBC Driver (Java and Binary Code) Vendor Specific Protocol JDBC Driver Types (2) Native API partly-Java Driver JDBC calls are converted into calls on the client API for DBMS This driver uses JavaNativeInterface(JNI) that calls the local database APIs The Native APIs partly-Java driver calls the Native Database Library that accesses the database This driver like the ODBC driver needs binary code on the client machine JDBC Driver (Java and Binary Code) Vendor Specific Protocol Database Server DB-client Basics of JDBC / 9 of 23

Networking protocol & middleware JDBC Driver Types (3) JDBC-Net pure Java driver Uses a networking protocol and middleware to communicate with the server Server then translates the messages communicated to DBMS specific function calls Specific protocol used depends on the vendor No need for client installation Allows access to multiple back-end databases Database Server Networking protocol & middleware JDBC Driver (Pure Java Driver) Database Server SQL Server DB-client Basics of JDBC / 10 of 23

Vendor Specific Protocol JDBC Driver Types (4) Native-protocol pure Java driver 100% Java enabled and does not use CLI libraries Capable of communicating directly with the database Converts JDBC calls into network protocols such as TCP/IP and other proprietary protocols used by DBMS directly Since many of these protocols are proprietary, the database vendors themselves will be the primary source of usage Vendor Specific Protocol JDBC Driver (Pure Java Driver) Database Server Basics of JDBC / 11 of 23 DB-client

JDBC architecture (1) Java Program JDBC Driver SQL command Results Application Server Database Basics of JDBC / 12 of 23

JDBC architecture (2) The JDBC API interface comprises of two layers: Application Layer – developer makes calls to database through SQL and retrieves results Driver layer – handles all communication with a specific driver implementation Four main Java interfaces that every Driver layer must implement are : Driver, Connection, Statement and ResultSet Basics of JDBC / 13 of 23

Implements Interfaces JDBC architecture (3) Application layer Driver layer Implements Interfaces Driver Connection Statement ResultSet Basics of JDBC / 14 of 23

JDBC components Application – here the JDBC methods are used to execute SQL and get results Driver Manager – to load specific drivers for an application Driver Data Source – User application interacts with this to get results Basics of JDBC / 15 of 23

The java.sql package JDBC API defines a set of interfaces and classes used for communicating with the database These are contained in the java.sql package Classes included in this package are : Date, DriverManager, DriverPropertyInfo, Time, TimeStamp, Types Interfaces included are : Callable Statement, Connection, DatabaseMetaData, Driver, PreparedStatement, ResultSet, ResultSetMetaData, Statement Basics of JDBC / 16 of 23

Creating a JDBC application Begin 1 Import the java.sql package 2 Load and Register the driver 3 Create a Connection object 4 Create a Statement object 5 Execute the statement 6 Close Connection 7 8 Basics of JDBC / 17 of 23 End

Example Output Basics of JDBC / 18 of 23

Using SQL (1) To retrieve the name, phone, email and phone number from the table colleagues: SELECT name, email, phone FROM colleagues To find out the number of employees who joined together on the same day and whose job_id is equal to 5: SELECT count(*) FROM Employee WHERE job_id=5 GROUP BY hire_date Basics of JDBC / 19 of 23

Using SQL (2) SQL DML statements do not return the results as ResultSets Instead they return an integer representing the number of rows affected Assume we need to add a new record – INSERT into COFFEE VALUES(‘French_Roast’,00049,8.99,0,0) Basics of JDBC / 20 of 23

Using SQL (3) The LIKE operator is used with SQL statements to compare two strings SELECT * FROM employee WHERE emp_id LIKE ‘A%’ Data Definition Language statements are used to create tables, add columns to the existing tables; delete tables and so on CREATE TABLE Emp(emp_name VARCHAR(25),emp_no VARCHAR(4),emp_age number); Basics of JDBC / 21 of 23

Example (1) Basics of JDBC / 22 of 23

Example (2) Output Basics of JDBC / 23 of 23