SlideShare a Scribd company logo
1 of 64
Department of Computer Science and Information
Atal Bihari Vajpayee Vishwavidyalaya
Ujjwal Matoliya
JDBC
Java Database Connectivity
INDEX
What is a JDBC ?
INDEX
What is a JDBC ?
Why Should We Use JDBC ?
INDEX
What is a JDBC ?
Why Should We Use JDBC ?
Why Should We Use Driver in JDBC ?
types of JDBC drivers
INDEX
What is a JDBC ?
Why Should We Use JDBC ?
Why Should We Use Driver in JDBC ?
Types of Drivers in JDBC
INDEX
What is a JDBC ?
Why Should We Use JDBC ?
Why Should We Use Driver in JDBC ?
Types of Drivers in JDBC
How to Establish a Data Base Connection and
Executing SQL Statement
Creator
Creator
User
Creator
User
Creator
User
Data
Creator
User
Data
Application
API
Application
API Data Base
Application
API
Data Base
JDBC stands for Java Database
Connectivity. JDBC is a Java API to
connect and execute the query with the
database. It is a part of JavaSE (Java
Standard Edition). JDBC API uses JDBC
drivers to connect with the database.
JDBC
JAVA
Application
API Data Base
JDBC
Driver
Why Should We Use JDBC
Before JDBC, ODBC API was the database API to connect and execute
the query with the database. But, ODBC API uses ODBC driver which is
written in C language (i.e. platform dependent and unsecured). That is
why Java has defined its own API (JDBC API) that uses JDBC drivers
(written in Java language).
We can use JDBC API to handle database using Java program and can
perform the following activities:
Connect to the database
Execute queries and update statements to the database
Retrieve the result received from the database.
JDBC Driver is a
software component
that enables java
application to interact
with the database.
JDBC Driver
There are four types of JDBC
drivers
JDBC-ODBC Bridge
Driver,
Native Driver,
Network Protocol Driver,
and
Thin Driver
The JDBC-ODBC bridge driver uses ODBC driver
to connect to the database. The JDBC-ODBC bridge
driver converts JDBC method calls into the ODBC
function calls. This is now discouraged because of
thin driver.
1.JDBC-ODBC Bridge Driver
Oracle does not support the JDBC-ODBC Bridge from Java 8. Oracle
recommends that you use JDBC drivers provided by the vendor of your
database instead of the JDBC-ODBC Bridge.
Advantages:
easy to use.
can be easily connected to any database.
Disadvantages:
Performance degraded because JDBC method call is converted into the
ODBC function calls.
The ODBC driver needs to be installed on the client machine.
The Native API driver uses the client-side
libraries of the database. The driver converts
JDBC method calls into native calls of the
database API. It is not written entirely in java.
2.Native API driver
Advantage:
performance upgraded than JDBC-ODBC
bridge driver.
Disadvantage:
The Native driver needs to be installed on the
each client machine.
The Vendor client library needs to be installed on
client machine.
The Network Protocol driver uses middleware
(application server) that converts JDBC calls directly
or indirectly into the vendor-specific database protocol.
It is fully written in java.
3.Network Protocol driver
Advantage:
No client side library is required because of
application server that can perform many tasks
like auditing, load balancing, logging etc.
Disadvantages:
Network support is required on client machine.
Requires database-specific coding to be done in
the middle tier.
Maintenance of Network Protocol driver becomes
costly because it requires database-specific coding
to be done in the middle tier.
The thin driver converts JDBC calls directly
into the vendor-specific database protocol. That
is why it is known as thin driver. It is fully
written in Java language.
4.Thin driver
Advantage:
Better performance than all other drivers.
No software is required at client side or
server side.
Disadvantage:
Drivers depend on the Database.
How to Establish a Data Base
Connection and Executing SQL
Statement
Database
Oracle
MySql DB
etc
There are 5 steps to connect any java
application with the database using JDBC.
These steps are as follows:
Register the Driver class
Create connection
Create statement
Execute queries
Close connection
Java Database Connectivity
1.)Register the driver class
The forName() method of Class class is used to
register the driver class. This method is used to
dynamically load the driver class.
public static void forName
(String className)throws
ClassNotFoundException
Class.forName("oracle.jdbc.driver.OracleDriver");
2.) Create the connection object
The getConnection() method of DriverManager class is
used to establish connection with the database.
Connection con=DriverManager.getConnection
( "jdbc:oracle:thin:@localhost:1521:xe","system","password");
1) public static Connection getConnection(String url)throws
SQLException
2) public static Connection getConnection(String url,String n
ame,String password)
throws SQLException
Example to establish connection with the Oracle database
3.) Create the Statement object
The createStatement ( ) method of Connection interface is
used to create statement. The object of statement is
responsible to execute queries with the database.
public Statement createStatement()throws SQLException
Example to create the statement object
Statement stmt=con.createStatement ();
4.)Execute the query
The executeQuery() method of Statement interface is
used to execute queries to the database. This method
returns the object of ResultSet that can be used to get all
the records of a table.
public ResultSet executeQuery(String sql)throws SQLException
Example to execute query
ResultSet rs=stmt.executeQuery("select * from emp");
while(rs.next()){
System.out.println(rs.getInt(1)+" "+rs.getString(2));
}
5.)Close the connection object
By closing connection object statement and Result Set
will be closed automatically. The close() method of
Connection interface is used to close the connection.
public void close()throws SQLException
Example to close connection
Con .close ();
 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
 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
 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
 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
 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
 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
 jdbc Java Database Connectivity ujjwal matoliya jdbc.pptx
 jdbc Java Database Connectivity ujjwal matoliya jdbc.pptx
 jdbc Java Database Connectivity ujjwal matoliya jdbc.pptx

More Related Content

Similar to jdbc Java Database Connectivity ujjwal matoliya jdbc.pptx

JDBC java database connectivity with dbms
JDBC java database connectivity with dbmsJDBC java database connectivity with dbms
JDBC java database connectivity with dbmsKhyalNayak
 
JDBC : Java Database Connectivity
JDBC : Java Database Connectivity JDBC : Java Database Connectivity
JDBC : Java Database Connectivity DevAdnani
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types pptkamal kotecha
 
creating jdbc connection
creating jdbc connectioncreating jdbc connection
creating jdbc connectionPaneliya Prince
 
creating jdbc connection
creating jdbc connectioncreating jdbc connection
creating jdbc connectionPaneliya Prince
 
chapter 5 java.pptx
chapter 5  java.pptxchapter 5  java.pptx
chapter 5 java.pptxBekiTube
 
Unit 5-jdbc2
Unit 5-jdbc2Unit 5-jdbc2
Unit 5-jdbc2msafad
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)suraj pandey
 
Introduction of java jdbc
Introduction of java jdbcIntroduction of java jdbc
Introduction of java jdbcfirstenquiry
 
Introduction of java jdbc
Introduction of java jdbcIntroduction of java jdbc
Introduction of java jdbcfirstenquiry
 
JDBC Presentation with JAVA code Examples.pdf
JDBC Presentation with JAVA code Examples.pdfJDBC Presentation with JAVA code Examples.pdf
JDBC Presentation with JAVA code Examples.pdfssuser8878c1
 
Chapter_4_-_JDBC[1].pptx
Chapter_4_-_JDBC[1].pptxChapter_4_-_JDBC[1].pptx
Chapter_4_-_JDBC[1].pptxBachaSirata
 

Similar to jdbc Java Database Connectivity ujjwal matoliya jdbc.pptx (20)

JDBC java database connectivity with dbms
JDBC java database connectivity with dbmsJDBC java database connectivity with dbms
JDBC java database connectivity with dbms
 
JDBC : Java Database Connectivity
JDBC : Java Database Connectivity JDBC : Java Database Connectivity
JDBC : Java Database Connectivity
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
 
Jdbc drivers
Jdbc driversJdbc drivers
Jdbc drivers
 
jdbc
jdbcjdbc
jdbc
 
creating jdbc connection
creating jdbc connectioncreating jdbc connection
creating jdbc connection
 
creating jdbc connection
creating jdbc connectioncreating jdbc connection
creating jdbc connection
 
Core jdbc basics
Core jdbc basicsCore jdbc basics
Core jdbc basics
 
chapter 5 java.pptx
chapter 5  java.pptxchapter 5  java.pptx
chapter 5 java.pptx
 
Unit 5-jdbc2
Unit 5-jdbc2Unit 5-jdbc2
Unit 5-jdbc2
 
JDBC-Introduction
JDBC-IntroductionJDBC-Introduction
JDBC-Introduction
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)
 
Jdbc
JdbcJdbc
Jdbc
 
Jdbc introduction
Jdbc introductionJdbc introduction
Jdbc introduction
 
Introduction of java jdbc
Introduction of java jdbcIntroduction of java jdbc
Introduction of java jdbc
 
Introduction of java jdbc
Introduction of java jdbcIntroduction of java jdbc
Introduction of java jdbc
 
Jdbc
JdbcJdbc
Jdbc
 
JDBC Presentation with JAVA code Examples.pdf
JDBC Presentation with JAVA code Examples.pdfJDBC Presentation with JAVA code Examples.pdf
JDBC Presentation with JAVA code Examples.pdf
 
java 4 Part 1 computer science.pptx
java 4 Part 1 computer science.pptxjava 4 Part 1 computer science.pptx
java 4 Part 1 computer science.pptx
 
Chapter_4_-_JDBC[1].pptx
Chapter_4_-_JDBC[1].pptxChapter_4_-_JDBC[1].pptx
Chapter_4_-_JDBC[1].pptx
 

More from ujjwalmatoliya

kisan bill ujjwal matoliya.pptx
kisan bill ujjwal matoliya.pptxkisan bill ujjwal matoliya.pptx
kisan bill ujjwal matoliya.pptxujjwalmatoliya
 
Data Frames and Scatterplots in R language ujjwal matoliya.pptx
Data Frames and Scatterplots in R language ujjwal matoliya.pptxData Frames and Scatterplots in R language ujjwal matoliya.pptx
Data Frames and Scatterplots in R language ujjwal matoliya.pptxujjwalmatoliya
 
Floyd’s and Warshal’s Algorithm ujjwal matoliya.pptx
Floyd’s and Warshal’s Algorithm ujjwal matoliya.pptxFloyd’s and Warshal’s Algorithm ujjwal matoliya.pptx
Floyd’s and Warshal’s Algorithm ujjwal matoliya.pptxujjwalmatoliya
 
congestion ujjwal matoliya.pptx
congestion ujjwal matoliya.pptxcongestion ujjwal matoliya.pptx
congestion ujjwal matoliya.pptxujjwalmatoliya
 
Global Attributes Window Event Attributes Form Events Ujjwal matoliya.pptx
Global Attributes Window Event Attributes Form Events Ujjwal matoliya.pptxGlobal Attributes Window Event Attributes Form Events Ujjwal matoliya.pptx
Global Attributes Window Event Attributes Form Events Ujjwal matoliya.pptxujjwalmatoliya
 
Instruction format UJJWAL MATOLIYA.pptx
Instruction format UJJWAL MATOLIYA.pptxInstruction format UJJWAL MATOLIYA.pptx
Instruction format UJJWAL MATOLIYA.pptxujjwalmatoliya
 
javascript function ujjwal matoliya.pptx
javascript function ujjwal matoliya.pptxjavascript function ujjwal matoliya.pptx
javascript function ujjwal matoliya.pptxujjwalmatoliya
 
string functions in SQL ujjwal matoliya.pptx
string functions in SQL ujjwal matoliya.pptxstring functions in SQL ujjwal matoliya.pptx
string functions in SQL ujjwal matoliya.pptxujjwalmatoliya
 
compiler design ujjwal matoliya 2nd sem MCA.pptx
compiler design ujjwal matoliya 2nd sem MCA.pptxcompiler design ujjwal matoliya 2nd sem MCA.pptx
compiler design ujjwal matoliya 2nd sem MCA.pptxujjwalmatoliya
 
3 address code ujjwal matoliya.pptx
3 address code ujjwal matoliya.pptx3 address code ujjwal matoliya.pptx
3 address code ujjwal matoliya.pptxujjwalmatoliya
 
2-3 tree ujjwal matoliya .pptx
2-3 tree ujjwal matoliya .pptx2-3 tree ujjwal matoliya .pptx
2-3 tree ujjwal matoliya .pptxujjwalmatoliya
 
Graph in Discrete mathemaetics.pptx
Graph in Discrete mathemaetics.pptxGraph in Discrete mathemaetics.pptx
Graph in Discrete mathemaetics.pptxujjwalmatoliya
 
Quick Sort in data structure.pptx
Quick Sort in data structure.pptxQuick Sort in data structure.pptx
Quick Sort in data structure.pptxujjwalmatoliya
 
Hadoop With R language.pptx
Hadoop With R language.pptxHadoop With R language.pptx
Hadoop With R language.pptxujjwalmatoliya
 
cyclomatic complecity.pptx
cyclomatic complecity.pptxcyclomatic complecity.pptx
cyclomatic complecity.pptxujjwalmatoliya
 
Congestion control algorithms.pptx
Congestion control algorithms.pptxCongestion control algorithms.pptx
Congestion control algorithms.pptxujjwalmatoliya
 
Game playing With AI.pptx
Game playing With AI.pptxGame playing With AI.pptx
Game playing With AI.pptxujjwalmatoliya
 

More from ujjwalmatoliya (20)

kisan bill ujjwal matoliya.pptx
kisan bill ujjwal matoliya.pptxkisan bill ujjwal matoliya.pptx
kisan bill ujjwal matoliya.pptx
 
Data Frames and Scatterplots in R language ujjwal matoliya.pptx
Data Frames and Scatterplots in R language ujjwal matoliya.pptxData Frames and Scatterplots in R language ujjwal matoliya.pptx
Data Frames and Scatterplots in R language ujjwal matoliya.pptx
 
Floyd’s and Warshal’s Algorithm ujjwal matoliya.pptx
Floyd’s and Warshal’s Algorithm ujjwal matoliya.pptxFloyd’s and Warshal’s Algorithm ujjwal matoliya.pptx
Floyd’s and Warshal’s Algorithm ujjwal matoliya.pptx
 
congestion ujjwal matoliya.pptx
congestion ujjwal matoliya.pptxcongestion ujjwal matoliya.pptx
congestion ujjwal matoliya.pptx
 
Global Attributes Window Event Attributes Form Events Ujjwal matoliya.pptx
Global Attributes Window Event Attributes Form Events Ujjwal matoliya.pptxGlobal Attributes Window Event Attributes Form Events Ujjwal matoliya.pptx
Global Attributes Window Event Attributes Form Events Ujjwal matoliya.pptx
 
Instruction format UJJWAL MATOLIYA.pptx
Instruction format UJJWAL MATOLIYA.pptxInstruction format UJJWAL MATOLIYA.pptx
Instruction format UJJWAL MATOLIYA.pptx
 
javascript function ujjwal matoliya.pptx
javascript function ujjwal matoliya.pptxjavascript function ujjwal matoliya.pptx
javascript function ujjwal matoliya.pptx
 
string functions in SQL ujjwal matoliya.pptx
string functions in SQL ujjwal matoliya.pptxstring functions in SQL ujjwal matoliya.pptx
string functions in SQL ujjwal matoliya.pptx
 
compiler design ujjwal matoliya 2nd sem MCA.pptx
compiler design ujjwal matoliya 2nd sem MCA.pptxcompiler design ujjwal matoliya 2nd sem MCA.pptx
compiler design ujjwal matoliya 2nd sem MCA.pptx
 
3 address code ujjwal matoliya.pptx
3 address code ujjwal matoliya.pptx3 address code ujjwal matoliya.pptx
3 address code ujjwal matoliya.pptx
 
2-3 tree ujjwal matoliya .pptx
2-3 tree ujjwal matoliya .pptx2-3 tree ujjwal matoliya .pptx
2-3 tree ujjwal matoliya .pptx
 
Graph in Discrete mathemaetics.pptx
Graph in Discrete mathemaetics.pptxGraph in Discrete mathemaetics.pptx
Graph in Discrete mathemaetics.pptx
 
Quick Sort in data structure.pptx
Quick Sort in data structure.pptxQuick Sort in data structure.pptx
Quick Sort in data structure.pptx
 
Hadoop With R language.pptx
Hadoop With R language.pptxHadoop With R language.pptx
Hadoop With R language.pptx
 
LOGIC FAMILY.pptx
LOGIC FAMILY.pptxLOGIC FAMILY.pptx
LOGIC FAMILY.pptx
 
Transaction.pptx
Transaction.pptxTransaction.pptx
Transaction.pptx
 
cyclomatic complecity.pptx
cyclomatic complecity.pptxcyclomatic complecity.pptx
cyclomatic complecity.pptx
 
Congestion control algorithms.pptx
Congestion control algorithms.pptxCongestion control algorithms.pptx
Congestion control algorithms.pptx
 
computer graphic.pptx
computer graphic.pptxcomputer graphic.pptx
computer graphic.pptx
 
Game playing With AI.pptx
Game playing With AI.pptxGame playing With AI.pptx
Game playing With AI.pptx
 

Recently uploaded

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 

Recently uploaded (20)

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 

jdbc Java Database Connectivity ujjwal matoliya jdbc.pptx

  • 1. Department of Computer Science and Information Atal Bihari Vajpayee Vishwavidyalaya Ujjwal Matoliya JDBC Java Database Connectivity
  • 3. INDEX What is a JDBC ? Why Should We Use JDBC ?
  • 4. INDEX What is a JDBC ? Why Should We Use JDBC ? Why Should We Use Driver in JDBC ? types of JDBC drivers
  • 5. INDEX What is a JDBC ? Why Should We Use JDBC ? Why Should We Use Driver in JDBC ? Types of Drivers in JDBC
  • 6. INDEX What is a JDBC ? Why Should We Use JDBC ? Why Should We Use Driver in JDBC ? Types of Drivers in JDBC How to Establish a Data Base Connection and Executing SQL Statement
  • 7.
  • 8.
  • 17. JDBC stands for Java Database Connectivity. JDBC is a Java API to connect and execute the query with the database. It is a part of JavaSE (Java Standard Edition). JDBC API uses JDBC drivers to connect with the database. JDBC
  • 19. Why Should We Use JDBC Before JDBC, ODBC API was the database API to connect and execute the query with the database. But, ODBC API uses ODBC driver which is written in C language (i.e. platform dependent and unsecured). That is why Java has defined its own API (JDBC API) that uses JDBC drivers (written in Java language). We can use JDBC API to handle database using Java program and can perform the following activities: Connect to the database Execute queries and update statements to the database Retrieve the result received from the database.
  • 20. JDBC Driver is a software component that enables java application to interact with the database. JDBC Driver
  • 21. There are four types of JDBC drivers JDBC-ODBC Bridge Driver, Native Driver, Network Protocol Driver, and Thin Driver
  • 22. The JDBC-ODBC bridge driver uses ODBC driver to connect to the database. The JDBC-ODBC bridge driver converts JDBC method calls into the ODBC function calls. This is now discouraged because of thin driver. 1.JDBC-ODBC Bridge Driver
  • 23. Oracle does not support the JDBC-ODBC Bridge from Java 8. Oracle recommends that you use JDBC drivers provided by the vendor of your database instead of the JDBC-ODBC Bridge. Advantages: easy to use. can be easily connected to any database. Disadvantages: Performance degraded because JDBC method call is converted into the ODBC function calls. The ODBC driver needs to be installed on the client machine.
  • 24. The Native API driver uses the client-side libraries of the database. The driver converts JDBC method calls into native calls of the database API. It is not written entirely in java. 2.Native API driver
  • 25. Advantage: performance upgraded than JDBC-ODBC bridge driver. Disadvantage: The Native driver needs to be installed on the each client machine. The Vendor client library needs to be installed on client machine.
  • 26. The Network Protocol driver uses middleware (application server) that converts JDBC calls directly or indirectly into the vendor-specific database protocol. It is fully written in java. 3.Network Protocol driver
  • 27. Advantage: No client side library is required because of application server that can perform many tasks like auditing, load balancing, logging etc. Disadvantages: Network support is required on client machine. Requires database-specific coding to be done in the middle tier. Maintenance of Network Protocol driver becomes costly because it requires database-specific coding to be done in the middle tier.
  • 28. The thin driver converts JDBC calls directly into the vendor-specific database protocol. That is why it is known as thin driver. It is fully written in Java language. 4.Thin driver
  • 29. Advantage: Better performance than all other drivers. No software is required at client side or server side. Disadvantage: Drivers depend on the Database.
  • 30. How to Establish a Data Base Connection and Executing SQL Statement
  • 32. There are 5 steps to connect any java application with the database using JDBC. These steps are as follows: Register the Driver class Create connection Create statement Execute queries Close connection Java Database Connectivity
  • 33. 1.)Register the driver class The forName() method of Class class is used to register the driver class. This method is used to dynamically load the driver class. public static void forName (String className)throws ClassNotFoundException Class.forName("oracle.jdbc.driver.OracleDriver");
  • 34. 2.) Create the connection object The getConnection() method of DriverManager class is used to establish connection with the database. Connection con=DriverManager.getConnection ( "jdbc:oracle:thin:@localhost:1521:xe","system","password"); 1) public static Connection getConnection(String url)throws SQLException 2) public static Connection getConnection(String url,String n ame,String password) throws SQLException Example to establish connection with the Oracle database
  • 35. 3.) Create the Statement object The createStatement ( ) method of Connection interface is used to create statement. The object of statement is responsible to execute queries with the database. public Statement createStatement()throws SQLException Example to create the statement object Statement stmt=con.createStatement ();
  • 36. 4.)Execute the query The executeQuery() method of Statement interface is used to execute queries to the database. This method returns the object of ResultSet that can be used to get all the records of a table. public ResultSet executeQuery(String sql)throws SQLException Example to execute query ResultSet rs=stmt.executeQuery("select * from emp"); while(rs.next()){ System.out.println(rs.getInt(1)+" "+rs.getString(2)); }
  • 37. 5.)Close the connection object By closing connection object statement and Result Set will be closed automatically. The close() method of Connection interface is used to close the connection. public void close()throws SQLException Example to close connection Con .close ();