Java Database Connectivity (JDBC)
JDBC is an API (Application Programming Interface) in Java that
allows a Java application to connect to and interact with databases. It
is a Java-based technology for accessing data stored in a database.
JDBC is part of the Java Standard Edition (Java SE) platform provided
by Oracle Corporation.
Features of JDBC
1. Standard API
o JDBC provides a common interface to interact with
databases.
o It is database-independent, meaning the same JDBC code
can work with different databases (like MySQL, Oracle,
SQL Server) without rewriting the application.
2. Platform-independent
o Most JDBC drivers are written in Java.
o JDBC works on any platform that supports Java.
3. CRUD and Complex Operations
o JDBC allows performing basic CRUD operations:
C – Create (INSERT)
R – Read (SELECT)
U – Update (UPDATE)
D – Delete (DELETE)
o It also supports complex operations like:
Joins
Stored procedures
Transactions
4. Vendor Support
o Many database vendors provide products and drivers that
are based on JDBC, ensuring wide support.
Need for JDBC Drivers
JDBC drivers are required to convert Java-specific calls to database-
specific calls and vice versa. Drivers act as a bridge between the Java
application and the database.
Type-1 Driver (JDBC-ODBC Bridge Driver)
Also called Bridge Driver.
Provided by Sun Microsystems as part of JDK.
Uses the ODBC driver internally to communicate with the
database.
Converts: JDBC calls → ODBC calls → Database-specific calls.
Works as a bridge between JDBC and ODBC.
Advantages
1. Easy to use and maintain.
2. No installation needed (built into JDK).
3. Database-independent since it does not talk to DB directly.
Disadvantages
1. Platform dependent (works mainly on Windows).
2. Slow performance due to multiple conversions.
3. Can connect only to local or local-network databases.
4. Supported only up to JDK 1.7.
Other Details
Driver Name: JDBC-ODBC Driver
Vendor: Sun & Intersolv
Driver Class: [Link]
URL Format: jdbc:odbc:<DSN>
Type-2 Driver (Native API Partly Java Driver)
Uses database-specific native libraries instead of ODBC.
Native libraries are written in non-Java languages (mostly C/C+
+).
The driver must be installed on the client machine.
Converts JDBC calls → native database calls that the DB engine
understands directly.
Advantages
1. Better performance than Type-1 (only one conversion step).
2. No need for ODBC drivers.
Disadvantages
1. Database dependent (tied to specific DB libraries).
2. Platform dependent (native code limits portability).
3. Requires installation of native libraries, and not all vendors
provide them.
Other Details
Driver Name: Native API / Part Java Part Native Driver
Vendor: Database vendor (e.g., Oracle)
Driver Class: [Link]
URL Format: jdbc:oracle:oci8:@tnsname
Installation Requirement: Oracle server + Oracle client setup
Environment Settings:
o PATH = d:\Oracle\Ora81\bin
o CLASSPATH = d:\Oracle\Ora81\jdbc\lib\[Link]
Type-3 Driver (Middleware / Java Net / Network Protocol
Driver)
Uses a middleware server to handle database communication.
JDBC calls are sent to the middleware using a database-
independent network protocol.
The middleware server then communicates with the actual
database and returns results.
The database can be changed without affecting the client (DB
abstraction).
Advantages
1. No client-side library installation required.
2. Middleware can handle additional services like logging, load
balancing, and security.
Disadvantages
1. Requires network support on the client machine.
2. Middle-tier needs database-specific coding.
3. Maintenance becomes costly and complex.
Other Details (Type-3 Driver)
Vendor: Third-party vendors like Intersolv
Software Requirement:
o IDS Server installation on the database server
o IDS Java libraries on client system ([Link])
Environment Settings:
o CLASSPATH = D:\IDSServer\classes\[Link]
Driver Class: [Link]
URL Format:
o jdbc:ids://abc:12/conn?dsn='SysOracleDSN'
o jdbc:ids://abc:12/conn?dsn='SysMySQLDSN'
Type-4 Driver (Pure Java / Thin Driver / Java Native Protocol Driver)
Fully written in Java.
Uses database-specific native protocol to communicate directly
with the database.
Converts JDBC calls directly into database-specific calls (no
intermediate layers).
No need for ODBC driver or native libraries, hence called a thin
driver.
Advantages
1. Best performance (only one level conversion).
2. Completely platform independent.
3. No client-side or server-side additional software required.
Disadvantage
Database dependent (driver must match the specific DB).
Other Details (Type-4 Driver)
Driver Name: Java Native Protocol Driver / Pure Java Driver
Vendor: Database vendor (e.g., Oracle, MySQL)
Software Requirement:
o DB server software installed on the server
o No client-side installation required except required Java
libraries (e.g., [Link])
Environment Settings:
o CLASSPATH = d:\Oracle\Ora81\jdbc\lib\[Link]
Driver Class: [Link]
URL Format: jdbc:oracle:thin:@host:1521:SID