FULL STACK WEB
DEVELOPMENT WITH JAVA
LECTURE-1
( I N T R O D U C T I O N TO J D B C )
Introduction To JDBC
Unofficial full-form of JDBC is Java Database Connectivity.
It is an API used for connecting programs written in Java with the
Relational Database.
Programs developed with Java/JDBC are platform and vendor
independent.
Introduction To JDBC
Some Popular RDBMS
Some of the most popular RDBMS are:
Oracle
MySQL
MS SQL Server
SQLite
PostgreSQL
IBM DB2
and many more
The Market Leader
Introduction To JDBC
History And Edition
• JDBC is maintained by JavaSoft, a sister concern of Oracle.
• It was released as a part of JDK 1.1 and was called JDBC 1.0.
• Later in 2006 , with Java 6, JDBC 4.0 was released
• Java SE 9 includes the latest version of JDBC called JDBC 4.3
How JDBC Maintains
Connection To The Database ?
• JDBC communicates with the database using a special set of
classes called Driver classes .
• These Driver classes perform the real communication with the
database in it’s native form.
• Further to manage these Driver classes the JDBC API provides
another top level class called DriverManager
How JDBC Maintains
Connection To The Database ?
JDBC Driver Types
Today, there are four types of JDBC drivers in use:
Type 1: JDBC-ODBC bridge Driver.
Type 2: Native Driver.
Type 3: Network API Driver
Type 4: Pure Java Driver
JDBC-ODBC Bridge Driver
• The JDBC-ODBC bridge driver uses ODBC driver to connect to the
database.
• ODBC stands for Open Database Connectivity and is a Microsoft
technology
• The JDBC-ODBC bridge driver converts JDBC method calls into
the ODBC function calls.
Architecture
JDBC-ODBC Bridge
A type 1 JDBC driver consists of a Java part that translates the
JDBC interface calls to ODBC calls.
An ODBC bridge then calls the ODBC driver of the given
database i.e. the driver converts JDBC method calls into ODBC
function calls.
Sun provides a JDBC-ODBC Bridge driver:
sun.jdbc.odbc.JdbcOdbcDriver.
Continued
JDBC-ODBC Bridge
Advantage:
Can be used to connect with variety of databases.
No installation required as it comes bundled with JDK.
Continued
JDBC-ODBC Bridge
Disadvantage:
This is the slowest driver.
Since it is a Microsoft technology so our Java application can
use it only when it runs on Windows platform.
It only supports basic SQL types like varchar2,number,date
but doesn’t supports advanced types like BLOB,CLOB etc
Continued
Native Driver
• A type 2 JDBC driver is like a type 1 driver, except the ODBC part is
replaced with a native code part instead.
• The native code part is targeted at a specific database product i.e.
uses the client-side libraries of the database product.
• The driver converts JDBC method calls into native calls of the
database native API.
Architecture
Native Driver
Advantage:
This architecture eliminated the need for the ODBC driver.
Directly calls the native client libraries shipped by the
database vendors
Continued
Native Driver
Disadvantage:
This is not pure java solution.
Although it is faster than type 1 driver but performance is still
slow because it uses JNI technology for native calls
Continued
Network Driver
• A type 3 JDBC driver is an all Java driver that sends the JDBC
interface calls to an intermediate server.
• The intermediate server then connects to the database on behalf
of the JDBC driver.
• The middle-tier (application server) converts JDBC calls directly or
indirectly into the vendor-specific database protocol.
Architecture
Network Driver
Advantage:
Type 3 drivers sought to be a 100% Java solution.
Type 3 drivers had a Java client component and a Java server
component, where the latter actually talked to the database.
Continued
Network Driver
Disadvantage:
Although this was technically a full Java solution, the
database vendors did not like this approach as it was costly –
they would have to rewrite their native client libraries which
were all C/C++.
In addition, this didn’t increase the architectural efficiency as
we are really still a 3 tier architecture
Continued
Pure Java Driver
It is also called thin driver or vendor specific driver.
This is because it converts JDBC calls directly into the vendor
specific database protocol.
Moreover it is fully written in Java language.
Continued
Architecture
Advantage And Disadvantage
ADVANTAGE:
Better performance
No middleware is needed while connecting to the database.
DISADVANTAGE:
Drivers are dependent on database.
There is a separate driver for each database.