SlideShare a Scribd company logo
1 of 21
SARDAR PATEL INSTITUTE OF
TECHNOLOGY AND MANAGEMENT
MANDLESHWAR

Submitted To
Proff.Aashutosh Yadav

Prepared by-:
Gayatri Patel
Enroll No.0881CS101009
CSE-Final year
TOPIC ON………………………..

INDUSTRIAL
INDUSTRIAL
TRAINING
TRAINING
ON
ON
J2EE
J2EE
CONTENTS
 Introduction
 Types of Driver
 JDBC Components
 JDBC Connection
JDBC – J ava D ata B ase C onnectivity
JDBC is a Java API that enables java program to
execute SQL Statements.
The JDBC API can also be used to interact with
multiple data sources in a distributed ,
heterogeneous environment.
JDBC
Driver

Java
Program

JDBC
API

Oracle
DB

Driver

SQL server
DB

Driver

MS-Access
DB
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)
JDBC – ODBC Bridge (Type 1)
Java
Application

ODBC
Layer

JDBC
API

Database
JDBC
ODBC Drivers

ODBC
API

Function –
Translate JDBC call to ODBC calls and send them to the ODBC database.
It is a java Wrapper developed over ODBC API.
Advantages - 1. Easily available as part of JDK
2. Easy to install.
Disadvantages- 1. slower in performance.
2. Limited to functionality of ODBC driver.
3. Not Recommended for production environment.
Native-API partly Java Driver(Type2)
Java
Application

JDBC
API

Vendor API

Database
JDBC Driver

Written partly in java & partly in native code.
It uses a mixture of Java implementation and vendor-specific native API’s to
provide data
access.
Uses native ‘c’ language lib calls for conversion.
Advantage – these offer better performance than jdbc-odbc bridge as layers are
less and it uses Native API which is database specific.
Disadvantage – not fully in java so portability issue , if database is changed than
native API must be changed as it is database specific.
Network Protocol All-Java Driver(type3)
Java
Client

JDBC
API

JDBC Driver
Server

Native Driver

Database
JDBC Driver

This driver is Server based. So, the Vendor DB lib. Is not required for clients.
Uses DB independent Protocol to communicate DB-requests to a Server component.
Translates requests into DB-specific Protocol.
Advantages- 1. fully written in java , hence portable.
2. The net protocol can be designed to make the client JDBC driver very small
and
fast to load.
3. most efficient amongst all drivers.
Disadvantages- 1. requires another server application to be installed and maintained.
acts

2. clients connect to DB servers via an intermediate server component that
as a gateway for multiple database servers.
Native Protocol All-Java Driver(type4)
Java
Client

JDBC
API

JDBC Driver

Database

•JDBC calls are directly converted to network protocol used by DBMS server
•It makes direct socket connections to the databases.
Advantages – 1.written in java only. So we can achieve platform independency.
2.number of translation layers are very less.
3.performance is good.

Disadvantages –
The user need a different driver for each database
JDBC Components
JDBC
There are seven standard steps in querying
databases:
1. Load the JDBC driver.
2. Define the connection URL.
3. Establish the connection.
4. Create a statement object.
5. Execute a query or update.
6. Process the results.
7. Close the connection.
Load the JDBC driver……………….
Only one time load in jdbc driver
How does one load a "class" into the Virtual
machine?
Use the static method Class.forName()

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
;
Package

ClassName
Define the connection URL………
•

Once a Driver is loaded, a connection can be made to the
database

•

The connection is defined by URL
• The URL has the following form:
• jdbc:driver:databasename

•

• Examples:
• jdbc:odbc:MyOdbcDatabase
• jdbc:postgres:WebsiteDatabase
• jdbc:oracle:CustomerInfo

A connection is obtained in the following manner:
• Connection conn =
DriverManager.getConnection("jdbc:odbc:MyDatabase“,"Usern
•

•

Establish the connection…….
The Connection interface defines many methods
for managing and using a connection to the
database
Connection aConnection;
• public Statement createStatement()
• public PreparedStatement

prepareStatement(String sql)
Create a statement object…….
The Statement interface .
• The most commonly used method is
createStatement()
• When an SQL statement is to be issued
against the database, a Statement object
must be created through the Connection
Connection aConnection;
Execute a query or update……
•

The Statement interface defines two methods
for executing SQL against the database
public ResultSet executeQuery(String sql)
public int executeUpdate(String sql)

•

executeQuery returns a ResultSet
• All rows and columns which match the query are contained

within the ResultSet
• The developer navigates through the ResultSet and uses the
data as required.
•

executeUpdate returns the number of rows
changed by the update statement
• This is used for insert statements, update statements and

delete statements
Close the connection………………..
rs.close();

aStmt.close();
Example
Code:
Connection aConnection;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException x)
{
System.out.println("Cannot find driver class. Check CLASSPATH");
return;
}
try
{
aConnection = DriverManager.getConnection("jdbc:odbc:MyDatabase“,"Username", "Password");
}
catch(SQLException x)
{
System.out.println("Exception connecting to database:" + x);
return;
}
Example Code
(continued):

try
{
Statement aStmt = aConnection.createStatement();
StringBuffer sb = new StringBuffer("SELECT Employee_id, Employee_Name");
sb.append(" FROM Employee WHERE EmployeeId>100");
ResultSet rs = aStmt.executeQuery(sb.toString());
while(rs.next())
{
int employeeId = rs.getInt(1);
String employeeName = rs.getString(2);
System.out.println("Id:" + employeeId + "nName:" + employeeName);
}
rs.close();
aStmt.close();
}
catch(SQLException x)
{
System.out.println("Exception while executing query:" + x);
}
THANKYOU !!
Any Query?

More Related Content

What's hot (20)

jdbc document
jdbc documentjdbc document
jdbc document
 
Java unit 14
Java unit 14Java unit 14
Java unit 14
 
Jdbc
JdbcJdbc
Jdbc
 
Jdbc
JdbcJdbc
Jdbc
 
java Jdbc
java Jdbc java Jdbc
java Jdbc
 
JDBC Connectivity Model
JDBC Connectivity ModelJDBC Connectivity Model
JDBC Connectivity Model
 
Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)
 
Jdbc
JdbcJdbc
Jdbc
 
jdbc
jdbcjdbc
jdbc
 
Database and Java Database Connectivity
Database and Java Database ConnectivityDatabase and Java Database Connectivity
Database and Java Database Connectivity
 
Unit 5-jdbc2
Unit 5-jdbc2Unit 5-jdbc2
Unit 5-jdbc2
 
Jdbc drivers
Jdbc driversJdbc drivers
Jdbc drivers
 
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
JDBC,Types of JDBC,Resultset, statements,PreparedStatement,CallableStatements...
 
Jdbc
JdbcJdbc
Jdbc
 
Jdbc_ravi_2016
Jdbc_ravi_2016Jdbc_ravi_2016
Jdbc_ravi_2016
 
Java- JDBC- Mazenet Solution
Java- JDBC- Mazenet SolutionJava- JDBC- Mazenet Solution
Java- JDBC- Mazenet Solution
 
Jdbc
JdbcJdbc
Jdbc
 
Java.sql package
Java.sql packageJava.sql package
Java.sql package
 
Jdbc
JdbcJdbc
Jdbc
 
Jdbcdriver
JdbcdriverJdbcdriver
Jdbcdriver
 

Viewers also liked

Viewers also liked (20)

Jdbc in java
Jdbc in javaJdbc in java
Jdbc in java
 
Different type of_software_testing - copy
Different type of_software_testing - copyDifferent type of_software_testing - copy
Different type of_software_testing - copy
 
Jdbc
JdbcJdbc
Jdbc
 
Software Process Models
Software Process ModelsSoftware Process Models
Software Process Models
 
02 software process_models
02 software process_models02 software process_models
02 software process_models
 
SDLC and Software Process Models
SDLC and Software Process ModelsSDLC and Software Process Models
SDLC and Software Process Models
 
Java Programming- Introduction to Java Applet Programs
Java Programming- Introduction to Java Applet ProgramsJava Programming- Introduction to Java Applet Programs
Java Programming- Introduction to Java Applet Programs
 
Types of Software testing
Types of  Software testingTypes of  Software testing
Types of Software testing
 
Jdbc
JdbcJdbc
Jdbc
 
Lecture03 p1
Lecture03 p1Lecture03 p1
Lecture03 p1
 
Unit testing
Unit testingUnit testing
Unit testing
 
Java applets
Java appletsJava applets
Java applets
 
Programacion con java
Programacion con javaProgramacion con java
Programacion con java
 
Introduction to the Servlet / JSP course
Introduction to the Servlet / JSP course Introduction to the Servlet / JSP course
Introduction to the Servlet / JSP course
 
Software quality assurance
Software quality assuranceSoftware quality assurance
Software quality assurance
 
Web application using JSP
Web application using JSPWeb application using JSP
Web application using JSP
 
Jdbc Dao it-slideshares.blogspot.com
Jdbc Dao it-slideshares.blogspot.comJdbc Dao it-slideshares.blogspot.com
Jdbc Dao it-slideshares.blogspot.com
 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
 
Jsp
JspJsp
Jsp
 
1 intro of data structure course
1  intro of data structure course1  intro of data structure course
1 intro of data structure course
 

Similar to jdbc

Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Pooja Talreja
 
JDBC java for learning java for learn.ppt
JDBC java for learning java for learn.pptJDBC java for learning java for learn.ppt
JDBC java for learning java for learn.pptkingkolju
 
jdbc-130913021409-phpapp01000988www.pptx
jdbc-130913021409-phpapp01000988www.pptxjdbc-130913021409-phpapp01000988www.pptx
jdbc-130913021409-phpapp01000988www.pptxssuser8878c1
 
java.pptx
java.pptxjava.pptx
java.pptxbfgd1
 
JDBC java database connectivity with dbms
JDBC java database connectivity with dbmsJDBC java database connectivity with dbms
JDBC java database connectivity with dbmsKhyalNayak
 
JDBC with MySQL.pdf
JDBC with MySQL.pdfJDBC with MySQL.pdf
JDBC with MySQL.pdfArumugam90
 
JDBC with MySQL.pdf
JDBC with MySQL.pdfJDBC with MySQL.pdf
JDBC with MySQL.pdfArumugam90
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySqlDhyey Dattani
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySqlDhyey Dattani
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types pptkamal kotecha
 
chapter 5 java.pptx
chapter 5  java.pptxchapter 5  java.pptx
chapter 5 java.pptxBekiTube
 
jdbc Java Database Connectivity ujjwal matoliya jdbc.pptx
 jdbc Java Database Connectivity ujjwal matoliya jdbc.pptx jdbc Java Database Connectivity ujjwal matoliya jdbc.pptx
jdbc Java Database Connectivity ujjwal matoliya jdbc.pptxujjwalmatoliya
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivityVaishali Modi
 

Similar to jdbc (20)

JDBC
JDBCJDBC
JDBC
 
Jdbc introduction
Jdbc introductionJdbc introduction
Jdbc introduction
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)
 
JDBC java for learning java for learn.ppt
JDBC java for learning java for learn.pptJDBC java for learning java for learn.ppt
JDBC java for learning java for learn.ppt
 
Chap3 3 12
Chap3 3 12Chap3 3 12
Chap3 3 12
 
jdbc-130913021409-phpapp01000988www.pptx
jdbc-130913021409-phpapp01000988www.pptxjdbc-130913021409-phpapp01000988www.pptx
jdbc-130913021409-phpapp01000988www.pptx
 
java.pptx
java.pptxjava.pptx
java.pptx
 
JDBC java database connectivity with dbms
JDBC java database connectivity with dbmsJDBC java database connectivity with dbms
JDBC java database connectivity with dbms
 
JDBC with MySQL.pdf
JDBC with MySQL.pdfJDBC with MySQL.pdf
JDBC with MySQL.pdf
 
JDBC with MySQL.pdf
JDBC with MySQL.pdfJDBC with MySQL.pdf
JDBC with MySQL.pdf
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
 
JDBC
JDBCJDBC
JDBC
 
Core jdbc basics
Core jdbc basicsCore jdbc basics
Core jdbc basics
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
 
chapter 5 java.pptx
chapter 5  java.pptxchapter 5  java.pptx
chapter 5 java.pptx
 
jdbc Java Database Connectivity ujjwal matoliya jdbc.pptx
 jdbc Java Database Connectivity ujjwal matoliya jdbc.pptx jdbc Java Database Connectivity ujjwal matoliya jdbc.pptx
jdbc Java Database Connectivity ujjwal matoliya jdbc.pptx
 
Chapter2 j2ee
Chapter2 j2eeChapter2 j2ee
Chapter2 j2ee
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
 

Recently uploaded

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 

Recently uploaded (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 

jdbc

  • 1. SARDAR PATEL INSTITUTE OF TECHNOLOGY AND MANAGEMENT MANDLESHWAR Submitted To Proff.Aashutosh Yadav Prepared by-: Gayatri Patel Enroll No.0881CS101009 CSE-Final year
  • 3. CONTENTS  Introduction  Types of Driver  JDBC Components  JDBC Connection
  • 4. JDBC – J ava D ata B ase C onnectivity JDBC is a Java API that enables java program to execute SQL Statements. The JDBC API can also be used to interact with multiple data sources in a distributed , heterogeneous environment.
  • 6. 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)
  • 7. JDBC – ODBC Bridge (Type 1) Java Application ODBC Layer JDBC API Database JDBC ODBC Drivers ODBC API Function – Translate JDBC call to ODBC calls and send them to the ODBC database. It is a java Wrapper developed over ODBC API. Advantages - 1. Easily available as part of JDK 2. Easy to install. Disadvantages- 1. slower in performance. 2. Limited to functionality of ODBC driver. 3. Not Recommended for production environment.
  • 8. Native-API partly Java Driver(Type2) Java Application JDBC API Vendor API Database JDBC Driver Written partly in java & partly in native code. It uses a mixture of Java implementation and vendor-specific native API’s to provide data access. Uses native ‘c’ language lib calls for conversion. Advantage – these offer better performance than jdbc-odbc bridge as layers are less and it uses Native API which is database specific. Disadvantage – not fully in java so portability issue , if database is changed than native API must be changed as it is database specific.
  • 9. Network Protocol All-Java Driver(type3) Java Client JDBC API JDBC Driver Server Native Driver Database JDBC Driver This driver is Server based. So, the Vendor DB lib. Is not required for clients. Uses DB independent Protocol to communicate DB-requests to a Server component. Translates requests into DB-specific Protocol. Advantages- 1. fully written in java , hence portable. 2. The net protocol can be designed to make the client JDBC driver very small and fast to load. 3. most efficient amongst all drivers. Disadvantages- 1. requires another server application to be installed and maintained. acts 2. clients connect to DB servers via an intermediate server component that as a gateway for multiple database servers.
  • 10. Native Protocol All-Java Driver(type4) Java Client JDBC API JDBC Driver Database •JDBC calls are directly converted to network protocol used by DBMS server •It makes direct socket connections to the databases. Advantages – 1.written in java only. So we can achieve platform independency. 2.number of translation layers are very less. 3.performance is good. Disadvantages – The user need a different driver for each database
  • 12. JDBC There are seven standard steps in querying databases: 1. Load the JDBC driver. 2. Define the connection URL. 3. Establish the connection. 4. Create a statement object. 5. Execute a query or update. 6. Process the results. 7. Close the connection.
  • 13. Load the JDBC driver………………. Only one time load in jdbc driver How does one load a "class" into the Virtual machine? Use the static method Class.forName() Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ; Package ClassName
  • 14. Define the connection URL……… • Once a Driver is loaded, a connection can be made to the database • The connection is defined by URL • The URL has the following form: • jdbc:driver:databasename • • Examples: • jdbc:odbc:MyOdbcDatabase • jdbc:postgres:WebsiteDatabase • jdbc:oracle:CustomerInfo A connection is obtained in the following manner: • Connection conn = DriverManager.getConnection("jdbc:odbc:MyDatabase“,"Usern
  • 15. • • Establish the connection……. The Connection interface defines many methods for managing and using a connection to the database Connection aConnection; • public Statement createStatement() • public PreparedStatement prepareStatement(String sql)
  • 16. Create a statement object……. The Statement interface . • The most commonly used method is createStatement() • When an SQL statement is to be issued against the database, a Statement object must be created through the Connection Connection aConnection;
  • 17. Execute a query or update…… • The Statement interface defines two methods for executing SQL against the database public ResultSet executeQuery(String sql) public int executeUpdate(String sql) • executeQuery returns a ResultSet • All rows and columns which match the query are contained within the ResultSet • The developer navigates through the ResultSet and uses the data as required. • executeUpdate returns the number of rows changed by the update statement • This is used for insert statements, update statements and delete statements
  • 19. Example Code: Connection aConnection; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch(ClassNotFoundException x) { System.out.println("Cannot find driver class. Check CLASSPATH"); return; } try { aConnection = DriverManager.getConnection("jdbc:odbc:MyDatabase“,"Username", "Password"); } catch(SQLException x) { System.out.println("Exception connecting to database:" + x); return; }
  • 20. Example Code (continued): try { Statement aStmt = aConnection.createStatement(); StringBuffer sb = new StringBuffer("SELECT Employee_id, Employee_Name"); sb.append(" FROM Employee WHERE EmployeeId>100"); ResultSet rs = aStmt.executeQuery(sb.toString()); while(rs.next()) { int employeeId = rs.getInt(1); String employeeName = rs.getString(2); System.out.println("Id:" + employeeId + "nName:" + employeeName); } rs.close(); aStmt.close(); } catch(SQLException x) { System.out.println("Exception while executing query:" + x); }