Dr R R DOCSIT, Dr BAMU. Basic Java : Introduction to JDBC 2 Objectives of This Session State what is Java Database Connectivity State different.

Slides:



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

Database programming in Java An introduction to Java Database Connectivity (JDBC)
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.
Distributed Application Development B. Ramamurthy.
1 C. Shahabi Application Programming for Relational Databases Cyrus Shahabi Computer Science Department University of Southern California
JDBC Java API for Database Connectivity. Layout of this recitation Introduction to JDBC API JDBC Architecture Understanding the design of JDBC API –Classes.
Objectives Describe JDBC Describe JDBC Driver Types
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.
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.
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.
What is JDBC? Java Database Connectivity (JDBC) is an API for the Java programming language that defines how a client may access a database. provides.
Database Programming in Java Corresponds with Chapter 32, 33.
JDBC. JDBC Drivers JDBC is an alternative to ODBC and ADO that provides database access to programs written in Java.
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,
CONTROLPANEL Java.sql package This package provides the APIs for accessing and processing data which is stored in the database especially relational.
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  The JDBC (Java Database Connectivity) API helps a Java program to access a database in a standard way  JDBC is a specification that tells the.
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.
WEB/DB1 DATABASE PROGRAMMING 3JDBC by the ASU Scholars.
JDBC Session 2 Tonight’s topics: 1.Prepared Statements 2.Transaction Processing 3.Callable Statements & Stored Procedures 4.Scrollable & Updatable Result.
JDBC – Java Database Concentricity
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.
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.
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.
JDBC
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.
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.
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 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.
Advanced Java Session 5 New York University School of Continuing and Professional Studies.
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.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Java Database Connectivity.
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.
JDBC. Database is used to store data permanently. These days almost all Applications needs database to store its data persistently. Below are the most.
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
Interacting with Database
JDBC Database Management Database connectivity
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:

Dr R R DOCSIT, Dr BAMU

Basic Java : Introduction to JDBC 2 Objectives of This Session State what is Java Database Connectivity State different types of drivers supported by JDBC Describe the steps to be followed for writing a simple JDBC application Describe the use of Resultset interface

Basic Java : Introduction to JDBC 3 JDBC Lets programmers connect to a database, query it or update through a Java application. Programs developed with Java & JDBC are platform & vendor independent. JDBC library is implemented in java.sql package.

Basic Java : Introduction to JDBC 4 JDBC A driver is a program that converts the Java method calls to the corresponding method calls understandable by the database in use.

Basic Java : Introduction to JDBC 5 JDBC Java Program JDBC API Oracle DB SQL server DB MS-Access DB Driver

Basic Java : Introduction to JDBC 6 ODBC A driver manager for managing drivers for SQL based databases. Developed by Microsoft to allow generic access to disparate database systems on windows platform. J2SDK comes with JDBC-to-ODBC bridge database driver to allow a java program to access any ODBC data source.

Basic Java : Introduction to JDBC 7 JDBC Vs ODBC ODBC is a ‘C’ API ODBC is hard to learn – because of low-level native ODBC. ODBC most suited for only Windows platform No platform independence

Basic Java : Introduction to JDBC 8 JDBC(Drivers) JDBC-ODBC Bridge (Type 1) Native-API partly Java Driver(Type 2) Net-Protocol All-Java Driver(Type 3) Native Protocol All-Java Driver(Type 4)

Basic Java : Introduction to JDBC 9 JDBC Driver Type 1 JDBC API JDBC ODBC Driver ODBC Layer Database Java Application ODBC API

Basic Java : Introduction to JDBC 10 Type 1 Driver (JDBC-ODBC Bridge driver) Translates all JDBC API calls to ODBC API calls. Relies on an ODBC driver to communicate with the database. Disadvantages  ODBC required hence all problems regarding ODBC follow.  Slow

Basic Java : Introduction to JDBC 11 JDBC Driver Type 2 JDBC Driver JDBC API Vendor API Database Java Application

Basic Java : Introduction to JDBC 12 Type 2 (Native lib to Java Implementation) Written partly in Java & partly in native code, that communicates with the client API of a database. Therefore, should install some platform-specific code in addition to Java library. The driver uses native ‘C’ lang lib calls for conversion.

Basic Java : Introduction to JDBC 13 JDBC Driver Type 3 Java Client Native Driver Database JDBC Driver Server JDBC API JDBC Driver

Basic Java : Introduction to JDBC 14 Type 3 (Pure Network Protocol Java Driver) Uses DB independent protocol to communicate DB-requests to a server component. This then translates requests into a DB-specific protocol. Since client is independent of the actual DB, deployment is simpler & more flexible.

Basic Java : Introduction to JDBC 15 JDBC Driver Type 4 Java Client JDBC Driver (Pure Java) Database Vendor-Specific Protocol JDBC API

Basic Java : Introduction to JDBC 16 Type 4 Driver (Pure Java Drivers) JDBC calls are directly converted to network protocol used by the DBMS server. Driver converts JDBC API calls to direct network calls using vendor-specific networking protocols by making direct socket connections with the DB. But driver usually comes only from DB-vendor.

Basic Java : Introduction to JDBC 17 JDBC API API layer has2 levels of interface.  Application layer: developer uses API to make calls to DB via SQL & retrieve results.  Driver layer : handles all communication with a specific Driver implementation.

Basic Java : Introduction to JDBC 18 Access Database ResultSet Oracle Database Sybase Database Application Oracle DriverSybase Driver PreparedStatement DriverManager ODBC Driver JDBC-ODBC Driver Statement CallableStatement Connection

Basic Java : Introduction to JDBC 19 JDBC URL Needed by drivers to locate,access and get other valid information about the databases. jdbc:driver:database-name  jdbc:Oracle:products  jdbc:odbc:STUD1  jdbc:odbc:Sybase  jdbc:odbc://whitehouse.gov.5000/cats;

Basic Java : Introduction to JDBC 20 JDBC(Interfaces) Driver Connection Statement PreparedStatement CallableStatement DatabaseMetadata ResultSet ResultSetMetadata

Basic Java : Introduction to JDBC 21 JDBC(Classes) Date DriverManager DriverPropertyInfo Time TimeStamp Types

Basic Java : Introduction to JDBC 22 Driver Interface Connection connect(String URL, Properties info)  Checks to see if URL is valid.  Opens a TCP connection to host & port number specified.  Returns an instance of Connection object. Boolean acceptsURL(String URL)

Basic Java : Introduction to JDBC 23 Driver Manager Class Connection getConnection(String URL) void registerDriver(Driver driver) void deregisterDriver() Eg : Connection conn = null; conn = DriverManager.getConnection(“jdbc:odbc:myds n”);

Basic Java : Introduction to JDBC 24 Connection Represents a session with the DB connection provided by driver. You use this object to execute queries & action statements & commit or rollback transactions.

Basic Java : Introduction to JDBC 25 JDBC(Connection) close() commit() void setAutoCommit(boolean b) rollback() Statement createStatement() CallableStatement prepareCall(String sql) PreparedStatement prepareStatement(String sql)

Basic Java : Introduction to JDBC 26 JDBC(Statement) Statement  PreparedStatement  CallableStatement Statement Methods boolean execute(String sql) ResultSet executeQuery(String sql) int executeUpdate(String sql)

Basic Java : Introduction to JDBC 27 JDBC(Stored Procedure) CREATE OR REPLACE PROCEDUE sp_interest ( id IN INTEGER bal IN OUT FLOAT ) AS BEGIN SELECT balance INTO bal FROM accounts WHERE account_id = id ; bal := bal + bal * 0.03 ; UPDATE accounts SET balance = bal WHERE account_id = id ; END;

Basic Java : Introduction to JDBC 28 JDBC(Stored Procedure) CallableStatement cstmt = con.prepareCall( “{ call sp_interest(?,?)} ”); cstmt.setInt(1,accountID); cstmt.setFloat(2, ); cstmt.registerOutParameter(2,Types.FLOAT); cstmt.execute(); System.out.println(cstmt.getFloat(2));

Basic Java : Introduction to JDBC 29 Java 2 Resultset Statement stmt = conn.createStatement(type, concurrency); TYPE_FORWARD_ONLY TYPE_SCROLL_INSENSITIVE TYPE_SCROLL_SENSITIVE CONCUR_READ_ONLY CONCUR_UPDATEABLE

Basic Java : Introduction to JDBC 30 JDBC(ResultSet) first() last() next() previous() beforeFirst() afterLast() absolute( int ) relative( int )

Basic Java : Introduction to JDBC 31 JDBC Statement stmt = con.createStatement(ResultSet.TYPE_SCRO LL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = stmt.executeQuery(“Select ….”); rs.first(); rs.updateInt(2, ); rs.updateRow();

Basic Java : Introduction to JDBC 32 JDBC ResultSet rs = stmt.executeQuery(“Select ….”); rs.moveToInsertRow(); rs.updateString(1, “fkjafla” ); rs.updateInt(2, 7686); rs.insertRow(); rs.last(); rs.deleteRow();

Basic Java : Introduction to JDBC 33 ResultSetMetadata Interface Object that can be used to find out about the types and properties of the columns in a ResultSet Example  Number of columns  Column title  Column type