SlideShare a Scribd company logo
1 of 22
Download to read offline
JDBC
Dev Adnani IU1983830001
JAVA DATABASE CONN.
Contents of the
Presentation
What Is JDBC
JDBC Architecture
What Is JDBC Driver
Types of JDBC Drivers
Configuration for JDBC connection
Configuration Properties For JDBC connection
Step for connection JDBC connection
What Is JDBC ?
JDBC == Java Database Connectivity
JDBC is used to connect java application with database.
JDBC is an API used to communicate Java application to database in database independent
and platform independent manner.
It provides classes and interfaces to connect or communicate Java application with database.
OTHER
MySQL
ORACLE
JDBC API
Java
Application
JDBC Architecture
JDBC
Driver
Manager
Driver
Driver
Driver
JDBC Driver
JDBC DRIVER is software component enabling a java
application to interact with a database.
It handles the communication with the database
server(oracle/mySQL).
we direct interect with the driver very rerely.
JDBC - ODBC (Bridge Driver)
Native - API Driver ( Partially java Driver)
Network Protocol Driver( Fully java Driver)
Thin Driver (Fully java Driver )
Type of JDBC driver!!
JDBC - ODBC (BRIDGE DRIVER)
Easy to use.
Can be easily connected to any database.
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 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.
Advantages:
Disadvantages:
NATIVE-API DRIVER
Performance upgraded than JDBC-ODBC bridge driver
The Native driver needs to be installed on the each client machine.
The Vendor client library needs to be installed on 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.
Advantage:
Disadvantage:
NETWORK PROTOCOL DRIVER
No client side library is required because of application server that can perform many tasks like
auditing, load balancing, logging etc.
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 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.
Advantage:
Disadvantages:
THIN DRIVER
Better performance.
No software is required .
Drivers depends on the Database.
The thin driver converts JDBC calls into the vendor-specific database protocol.
It is fully written in Java language.
Advantage:
Disadvantage:
Configuration Properties For JDBC connection
Driver Manager
Connection
Prepared Statement
Result Set
SQLException
DRIVER MANAGER
It matches connection requests from the java
application with the proper database driver using
communication sub-protocol.
The first driver that recognize certain sub-
protocol under JDBC will be used to establish a
database connection.
CONNECTION
Connection interface has all methods for contacting a database
The connection object represent communication context.
All communication with database is through connection object only.
PREPARED STATEMENT
Prepared Statement is an interface for representing SQL statement.
SQL statement is Precompiled and stored in a Prepared Statement object
Object can then be used efficiently execute this statement multiple time
RESULT SET
ResultSet - RS is an interface to represent a database table
These objects holds data retrieved from a database after you execute SQL query using
statement object.
It acts as an iterator to allow you to move through its data.
Step for JDBC connection
Loading driver
Establishing connection
Preparing statement
Executing statement
Getting result
Close DB
1. LOADING THE DRIVER
Class.forName() : Here we load the driver’s class file into memory at the
runtime. No need of using new or creation of object .The following example
uses Class.forName() to load the Oracle driver –
DriverManager.registerDriver(): DriverManager is a Java inbuilt class with a
static member register. Here we call the constructor of the driver class at
compile time . The following example uses DriverManager.registerDriver()to
register the Oracle driver –
- Class.forName(“oracle.jdbc.driver.OracleDriver”);
- DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
2. CREATE THE CONNECTIONS
Connection con = DriverManager.getConnection(url,user,password)
user – username from which your sql command prompt can be accessed.
password – password from which your sql command prompt can be accessed.
url : Uniform Resource Locator. It can be created as follows:
String url = “ jdbc:oracle:thin:@localhost:1521:xe”
3. CREATE A STATEMENT
Once a connection is established you can interact with the database. The
JDBCStatement, CallableStatement, and PreparedStatement interfaces define
the methods that enable you to send SQL commands and receive data from
your database.
Statement st = con.createStatement();
4. EXECUTE THE QUERY
Query for updating / inserting table in a database.
Query for retrieving data .
The executeQuery() method of Statement interface is used to execute queries
of retrieving values from the database. This method returns the object of
ResultSet that can be used to get all the records of a table.
ResultSet rset = null;
rset = st.executeQuery("select last_name, first_name from person");
5.CLOSE THE CONNECTIONS
we have sent the data to the specified location and now we are at the verge of
completion of our task .
By closing connection, objects of Statement and ResultSet will be closed
automatically. The close() method of Connection interface is used to close the
connection.
con.close();
Thank You
Any Questions?
ADNANI DEV
IU1983830001

More Related Content

What's hot (20)

Open Source Ajax Solution @OSDC.tw 2009
Open Source Ajax  Solution @OSDC.tw 2009Open Source Ajax  Solution @OSDC.tw 2009
Open Source Ajax Solution @OSDC.tw 2009
 
SQL
SQLSQL
SQL
 
Java J2EE
Java J2EEJava J2EE
Java J2EE
 
Javascript
JavascriptJavascript
Javascript
 
Layouts in android
Layouts in androidLayouts in android
Layouts in android
 
Implicit object.pptx
Implicit object.pptxImplicit object.pptx
Implicit object.pptx
 
What Is Virtual DOM In React JS.pptx
What Is Virtual DOM In React JS.pptxWhat Is Virtual DOM In React JS.pptx
What Is Virtual DOM In React JS.pptx
 
Hibernate architecture
Hibernate architectureHibernate architecture
Hibernate architecture
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Jdbc Ppt
Jdbc PptJdbc Ppt
Jdbc Ppt
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
Asp Architecture
Asp ArchitectureAsp Architecture
Asp Architecture
 
Java database connectivity with MYSQL
Java database connectivity with MYSQLJava database connectivity with MYSQL
Java database connectivity with MYSQL
 
Workshop 21: React Router
Workshop 21: React RouterWorkshop 21: React Router
Workshop 21: React Router
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
 
Android adapters
Android adaptersAndroid adapters
Android adapters
 

Similar to JDBC Driver Types and Connection Configuration in 38 Characters

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 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
 
chapter 5 java.pptx
chapter 5  java.pptxchapter 5  java.pptx
chapter 5 java.pptxBekiTube
 
creating jdbc connection
creating jdbc connectioncreating jdbc connection
creating jdbc connectionPaneliya Prince
 
creating jdbc connection
creating jdbc connectioncreating jdbc connection
creating jdbc connectionPaneliya Prince
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)suraj pandey
 
Fundamentals of JDBC
Fundamentals of JDBCFundamentals of JDBC
Fundamentals of JDBCJainul Musani
 
Unit 5-jdbc2
Unit 5-jdbc2Unit 5-jdbc2
Unit 5-jdbc2msafad
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types pptkamal kotecha
 
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 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
 

Similar to JDBC Driver Types and Connection Configuration in 38 Characters (20)

Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Jdbc introduction
Jdbc introductionJdbc introduction
Jdbc introduction
 
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 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
 
chapter 5 java.pptx
chapter 5  java.pptxchapter 5  java.pptx
chapter 5 java.pptx
 
creating jdbc connection
creating jdbc connectioncreating jdbc connection
creating jdbc connection
 
creating jdbc connection
creating jdbc connectioncreating jdbc connection
creating jdbc connection
 
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)
 
Fundamentals of JDBC
Fundamentals of JDBCFundamentals of JDBC
Fundamentals of JDBC
 
Unit 5-jdbc2
Unit 5-jdbc2Unit 5-jdbc2
Unit 5-jdbc2
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
 
JDBC java database connectivity with dbms
JDBC java database connectivity with dbmsJDBC java database connectivity with dbms
JDBC java database connectivity with dbms
 
Rajesh jdbc
Rajesh   jdbcRajesh   jdbc
Rajesh jdbc
 
jdbc
jdbcjdbc
jdbc
 
Java jdbc
Java jdbcJava jdbc
Java 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
 

More from DevAdnani

Joker Analysis
Joker AnalysisJoker Analysis
Joker AnalysisDevAdnani
 
Coding principles
Coding principles Coding principles
Coding principles DevAdnani
 
Amazon Case Study 2021
Amazon Case Study 2021Amazon Case Study 2021
Amazon Case Study 2021DevAdnani
 
Transport layer security
Transport layer securityTransport layer security
Transport layer securityDevAdnani
 
Data mining
 Data mining Data mining
Data miningDevAdnani
 
Abstarction & Encapsulation
Abstarction & EncapsulationAbstarction & Encapsulation
Abstarction & EncapsulationDevAdnani
 
Security issues in os
Security issues in osSecurity issues in os
Security issues in osDevAdnani
 
Women entrepreneurship
Women entrepreneurship Women entrepreneurship
Women entrepreneurship DevAdnani
 

More from DevAdnani (8)

Joker Analysis
Joker AnalysisJoker Analysis
Joker Analysis
 
Coding principles
Coding principles Coding principles
Coding principles
 
Amazon Case Study 2021
Amazon Case Study 2021Amazon Case Study 2021
Amazon Case Study 2021
 
Transport layer security
Transport layer securityTransport layer security
Transport layer security
 
Data mining
 Data mining Data mining
Data mining
 
Abstarction & Encapsulation
Abstarction & EncapsulationAbstarction & Encapsulation
Abstarction & Encapsulation
 
Security issues in os
Security issues in osSecurity issues in os
Security issues in os
 
Women entrepreneurship
Women entrepreneurship Women entrepreneurship
Women entrepreneurship
 

Recently uploaded

Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
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
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
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
 
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
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
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
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 

Recently uploaded (20)

Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
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
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
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
 
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
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
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
 
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
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 

JDBC Driver Types and Connection Configuration in 38 Characters

  • 2. Contents of the Presentation What Is JDBC JDBC Architecture What Is JDBC Driver Types of JDBC Drivers Configuration for JDBC connection Configuration Properties For JDBC connection Step for connection JDBC connection
  • 3. What Is JDBC ? JDBC == Java Database Connectivity JDBC is used to connect java application with database. JDBC is an API used to communicate Java application to database in database independent and platform independent manner. It provides classes and interfaces to connect or communicate Java application with database.
  • 5. JDBC Driver JDBC DRIVER is software component enabling a java application to interact with a database. It handles the communication with the database server(oracle/mySQL). we direct interect with the driver very rerely.
  • 6. JDBC - ODBC (Bridge Driver) Native - API Driver ( Partially java Driver) Network Protocol Driver( Fully java Driver) Thin Driver (Fully java Driver ) Type of JDBC driver!!
  • 7. JDBC - ODBC (BRIDGE DRIVER) Easy to use. Can be easily connected to any database. 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 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. Advantages: Disadvantages:
  • 8. NATIVE-API DRIVER Performance upgraded than JDBC-ODBC bridge driver The Native driver needs to be installed on the each client machine. The Vendor client library needs to be installed on 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. Advantage: Disadvantage:
  • 9. NETWORK PROTOCOL DRIVER No client side library is required because of application server that can perform many tasks like auditing, load balancing, logging etc. 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 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. Advantage: Disadvantages:
  • 10. THIN DRIVER Better performance. No software is required . Drivers depends on the Database. The thin driver converts JDBC calls into the vendor-specific database protocol. It is fully written in Java language. Advantage: Disadvantage:
  • 11. Configuration Properties For JDBC connection Driver Manager Connection Prepared Statement Result Set SQLException
  • 12. DRIVER MANAGER It matches connection requests from the java application with the proper database driver using communication sub-protocol. The first driver that recognize certain sub- protocol under JDBC will be used to establish a database connection.
  • 13. CONNECTION Connection interface has all methods for contacting a database The connection object represent communication context. All communication with database is through connection object only.
  • 14. PREPARED STATEMENT Prepared Statement is an interface for representing SQL statement. SQL statement is Precompiled and stored in a Prepared Statement object Object can then be used efficiently execute this statement multiple time
  • 15. RESULT SET ResultSet - RS is an interface to represent a database table These objects holds data retrieved from a database after you execute SQL query using statement object. It acts as an iterator to allow you to move through its data.
  • 16. Step for JDBC connection Loading driver Establishing connection Preparing statement Executing statement Getting result Close DB
  • 17. 1. LOADING THE DRIVER Class.forName() : Here we load the driver’s class file into memory at the runtime. No need of using new or creation of object .The following example uses Class.forName() to load the Oracle driver – DriverManager.registerDriver(): DriverManager is a Java inbuilt class with a static member register. Here we call the constructor of the driver class at compile time . The following example uses DriverManager.registerDriver()to register the Oracle driver – - Class.forName(“oracle.jdbc.driver.OracleDriver”); - DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
  • 18. 2. CREATE THE CONNECTIONS Connection con = DriverManager.getConnection(url,user,password) user – username from which your sql command prompt can be accessed. password – password from which your sql command prompt can be accessed. url : Uniform Resource Locator. It can be created as follows: String url = “ jdbc:oracle:thin:@localhost:1521:xe”
  • 19. 3. CREATE A STATEMENT Once a connection is established you can interact with the database. The JDBCStatement, CallableStatement, and PreparedStatement interfaces define the methods that enable you to send SQL commands and receive data from your database. Statement st = con.createStatement();
  • 20. 4. EXECUTE THE QUERY Query for updating / inserting table in a database. Query for retrieving data . The executeQuery() method of Statement interface is used to execute queries of retrieving values from the database. This method returns the object of ResultSet that can be used to get all the records of a table. ResultSet rset = null; rset = st.executeQuery("select last_name, first_name from person");
  • 21. 5.CLOSE THE CONNECTIONS we have sent the data to the specified location and now we are at the verge of completion of our task . By closing connection, objects of Statement and ResultSet will be closed automatically. The close() method of Connection interface is used to close the connection. con.close();