JDBC - Java Database Connectivity. JDBC provides Java applications with access to most database systems via SQL The architecture and API closely resemble.

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.
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.
SQL (Structured Query Language) X/OPEN Call Level Interface For SQL ODBC (Open DataBase Connectivity) API JDBC (Java DataBase Connectivity) API SQL (Structured.
1 JDBC Java Database Connectivity. 2 c.pdf
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.
UFCE4Y UFCE4Y-20-3 Components and Services Julia Dawson.
Java MS Access database connectivity Follow these steps: 1)Go to the start->Control Panel->Administrative Tools- > data sources. 2)Click Add button and.
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. –
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.
Java Database Connectivity Vijayan Sugumaran Department of DIS Oakland University.
© Wang Bin 2004 JDBC ----Java Database Connectivity.
1 Java DataBase Connectivity JDBC java.sql.*. 2 Java DataBase Connectivity Draft release of JDBC spec (3/96) Java API for executing SQL statements (Since.
JDBC. JDBC Drivers JDBC is an alternative to ODBC and ADO that provides database access to programs written in Java.
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.
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.
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.
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.
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.
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–
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
Basics of JDBC.
Basics of JDBC Session 14.
JDBC (Java Database Connectivity)
JDBC Chapter 1 JDBC Introduction
Advanced Java Session 5 New York University School of Continuing and Professional Studies.
Ch. NoNameMarks 01AWT24 02Networking18 03JDBC20 04Swing18 05Servlet20 Advance Java Programming.
Umair Javed©2005 Enterprise Application Development Java Database Connectivity (JDBC) JDBC1.
1 JDBC – Java Database Connectivity CS , Spring 2010.
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.
DEPTT. OF COMP. SC & APPLICATIONS
Interacting with Database
Lec - 14.
JDBC 15-Apr-18.
JDBC Database Management Database connectivity
JDBC 21-Aug-18.
Introduction to Programming with Java
JDBC 15-Nov-18.
Mr. Harish Sharma Asst. Professor Dept. of CA & IT SGRRITS Dehradun
Interacting with Database
JDBC – ODBC DRIVERS.
Java Database Connectivity
Java API for Database Connectivity
JDBC Example.
Presentation transcript:

JDBC - Java Database Connectivity

JDBC provides Java applications with access to most database systems via SQL The architecture and API closely resemble Microsoft's ODBC (Open DataBase Connectivity) JDBC 1.0 was originally introduced into Java 1.1 JDBC 2.0 was added to Java 1.2 and so on.. JDBC 4.0 is the latest version. JDBC classes are contained within the java.sql & javax.sql packages. There are few classes There are several interfaces What is JDBC?

With JDBC, the application programmer uses the JDBC API The developer never uses any proprietary APIs Any proprietary APIs are implemented by a JDBC driver There are 4 types of JDBC Drivers JDBC Architecture Java Application JDBC API JDBC DriverManager JDBC Driver

JDBC Architecture ApplicationJDBCDriver Java code calls JDBC library JDBC loads a driver Driver talks to a particular database Can have more than one driver -> more than one database.

JDBC Classes DriverManager Manages JDBC Drivers Used to Obtain a connection to a Database Date Used to Map between java.util.Date and the SQL DATE type Time Used to Map between java.util.Date and the SQL TIME type

JDBC Interfaces Driver All JDBC Drivers must implement the Driver interface. Used to obtain a connection to a specific database type Connection Represents a connection to a specific database Used for creating statements Used for managing database transactions Used for accessing stored procedures Used for creating callable statements ResultSet Represents the result of an SQL statement Provides methods for navigating through the resulting data

JDBC Interfaces Statement Used for executing SQL statements against the database PreparedStatement Similar to a stored procedure An SQL statement (which can contain parameters) is compiled and stored in the database CallableStatement Used for executing stored procedures

There are 4 types of JDBC Drivers Type 1 - JDBC-ODBC Bridge Type 2 - JDBC-Native Bridge Type 3 - JDBC-Net Bridge Type 4 - Direct JDBC Driver Type 1 only runs on platforms where ODBC is available ODBC must be configured separately Type 2 Drivers map between a proprietary Database API and the JDBC API Type 3 Drivers are used with middleware products Type 4 Drivers are written in Java In most cases, type 4 drivers are preferred JDBC Drivers

Application GUI Network Interface JDBC API Database Server Client SQL Requests SQL Results SQL Requests Network Connection JDBC API defines a set of interfaces and classes to be used for communicating with a database.

Application Network Interface JDBC Driver Database Server Client SQL Requests SQL Results SQL Requests Network Connection JDBC Driver: translates java into SQL. JDBC drivers are implemented by database vendors. JDBC supports the ANSI SQL92 Entry Level standard. Database Libraries

JDBC Driver Types: Driver TypeDescription 1. ODBC-JDBC BridgeMap JDBC calls to ODBC driver calls on the client. 2. Native API-Part JavaMaps JDBC calls to native calls on the client. 3. JDBC Network-All JavaMaps JDBC calls to network protocol, which calls native methods on server. 4. Native Protocol-All JavaDirectly calls RDBMS from the client machine.

Application JDBC Driver Database Client SQL Requests SQL Results Stand-Alone Applications run on Local Machine JDBC Driver: translates java calls into ODBC calls. Harder to debug, slower, not work for applets. Inexpensive, readily available. ODBC Driver Type I: JDBC-ODBC Bridge Driver Network Interface Local Disk Proprietary Database Protocol Network Interface Server

Application JDBC Driver Database Client SQL Requests SQL Results JDBC Driver: use local libraries to communicate with database server. Java calls are translated into local CLI calls. Faster than the ODBC bridge, not work for applets. Native Database Libraries (Call Level Interface) Type II: Native-API-Partly Java Driver Network Interface Local Disk Proprietary Database Protocol Network Interface Server

Application Database Client SQL Requests SQL Results JDBC Driver: client calls are translated into driver-specific network protocol. JDBC Driver: server listener translates the requests into CLI calls at server site. All database-specific code resides on the server. JDBC driver network protocol is not standardized. JDBC Driver (Client) Type III: JDBC-Net-All-Java Driver Network Interface Local Disk JDBC Driver Network Protocol Network Interface Server JDBC Driver (Server Listener) Native Database Libraries (Call Level Interface)

Application Database Client SQL Requests SQL Results JDBC Driver: 100% java and use no CLI native libraries. Support applets containing the driver to be downloaded over the network, I.e., applets can communicate directly with the database. JDBC Driver Type IV: Native-Protocol-All-Java Driver Network Interface Local Disk Proprietary DB Protocol (in Java) Network Interface Server

JDBC Drivers (Fig.) JDBC Type I “Bridge” Type II “Native” Type III “Middleware” Type IV “Pure” ODBC Driver CLI (.lib) Middleware Server

SQL Types/Java Types Mapping SQL TypeJava Type CHARString VARCHARString LONGVARCHARString NUMERICjava.Math.BigDecimal DECIMALjava.Math.BigDecimal BITboolean TINYINTint SMALLINTint INTEGERint BIGINTlong REALfloat FLOATdouble DOUBLEdouble BINARYbyte[] VARBINARYbyte[] DATEjava.sql.Date TIMEjava.sql.Time

Steps To execute a statement against a database, the following flow is observed Load the driver (Only performed once) Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Obtain a Connection to the database (Save for later use) Connection con = DriverManager.getConnection("jdbc:odbc:DSN"); Obtain a Statement object from the Connection Statement st=con.createStatement() PreparedStatement pst=con.prepareStatement(String sql) Use the Statement object to execute SQL. Updates, inserts and deletes return Boolean. Selects return a ResultSet ResultSet rs=st.executeQuery(String sql) Navigate ResultSet, using data as required public int getInt(int columnNumber) public String getString(String columnName) Close Connection. con.close()

import java.sql.*; class Conn1 { public static void main(String[] args) { ResultSet rs; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c=DriverManager.getConnection("jdbc:odbc:mydsn"); Statement st=c.createStatement(); rs=st.executeQuery("select * from stud1"); System.out.println("Name" +"\t"+"Roll"); while(rs.next()) { System.out.println(rs.getString("Name")+"\t"+rs.getInt("Roll")); } c.close(); } catch(Exception e) { System.out.println(e); }